iOS UILabel
来源:互联网 发布:淘宝买家数据采集 编辑:程序博客网 时间:2024/05/16 15:36
这里我们继续介绍下UILabel
首先我们看看UILabel.h文件,给我们提供了什么东西?
//
// UILabel.h
// UIKit
//
// Copyright (c) 2006-2013, Apple Inc. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <CoreGraphics/CoreGraphics.h>
#import <UIKit/UIView.h>
#import <UIKit/UIStringDrawing.h>
#import <UIKit/UIKitDefines.h>
@class UIColor, UIFont;
NS_CLASS_AVAILABLE_IOS(2_0) @interface UILabel : UIView <NSCoding>
@property(nonatomic,copy) NSString *text; // default is nil
@property(nonatomic,retain) UIFont *font; // default is nil (system font 17 plain)
@property(nonatomic,retain) UIColor *textColor; // default is nil (text draws black)
@property(nonatomic,retain) UIColor *shadowColor; // default is nil (no shadow)
@property(nonatomic) CGSize shadowOffset; // default is CGSizeMake(0, -1) -- a top shadow
@property(nonatomic) NSTextAlignment textAlignment; // default is NSTextAlignmentLeft
@property(nonatomic) NSLineBreakMode lineBreakMode; // default is NSLineBreakByTruncatingTail. used for single and multiple lines of text
// the underlying attributed string drawn by the label, if set, the label ignores the properties above.
@property(nonatomic,copy) NSAttributedString *attributedText NS_AVAILABLE_IOS(6_0); // default is nil
// the 'highlight' property is used by subclasses for such things as pressed states. it's useful to make it part of the base class as a user property
@property(nonatomic,retain) UIColor *highlightedTextColor; // default is nil
@property(nonatomic,getter=isHighlighted) BOOL highlighted; // default is NO
@property(nonatomic,getter=isUserInteractionEnabled) BOOL userInteractionEnabled; // default is NO
@property(nonatomic,getter=isEnabled) BOOL enabled; // default is YES. changes how the label is drawn
// this determines the number of lines to draw and what to do when sizeToFit is called. default value is 1 (single line). A value of 0 means no limit
// if the height of the text reaches the # of lines or the height of the view is less than the # of lines allowed, the text will be
// truncated using the line break mode.
@property(nonatomic) NSInteger numberOfLines;
// these next 3 property allow the label to be autosized to fit a certain width by scaling the font size(s) by a scaling factor >= the minimum scaling factor
// and to specify how the text baseline moves when it needs to shrink the font.
@property(nonatomic) BOOL adjustsFontSizeToFitWidth; // default is NO
@property(nonatomic) BOOL adjustsLetterSpacingToFitWidth NS_DEPRECATED_IOS(6_0,7_0); // deprecated - hand tune by using NSKernAttributeName to affect tracking
@property(nonatomic) CGFloat minimumFontSize NS_DEPRECATED_IOS(2_0, 6_0); // NOTE: deprecated - use minimumScaleFactor. default is 0.0
@property(nonatomic) UIBaselineAdjustment baselineAdjustment; // default is UIBaselineAdjustmentAlignBaselines
@property(nonatomic) CGFloat minimumScaleFactor NS_AVAILABLE_IOS(6_0); // default is 0.0
// override points. can adjust rect before calling super.
// label has default content mode of UIViewContentModeRedraw
- (CGRect)textRectForBounds:(CGRect)bounds limitedToNumberOfLines:(NSInteger)numberOfLines;
- (void)drawTextInRect:(CGRect)rect;
// Support for constraint-based layout (auto layout)
// If nonzero, this is used when determining -intrinsicContentSize for multiline labels
@property(nonatomic) CGFloat preferredMaxLayoutWidth NS_AVAILABLE_IOS(6_0);
@end
Label 常用的属性以及方法
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
// 创建UILabel
UILabel * label = [[UILabel alloc] init];
// 设置label.frame
label.frame = CGRectMake(0, 100, self.view.frame.size.width, 40);
// 设置文本内容
label.text = @"程序创建的label";
// 设置文本居中
label.textAlignment = NSTextAlignmentCenter;
// 设置字体颜色
label.textColor = [UIColor redColor];
// 设置字体大小
label.font = [UIFont systemFontOfSize:14];
// 添加至视图中
[self.view addSubview:label];
}
0 0
- IOS-UILabel
- ios Uilabel
- IOS UILabel
- IOS(UILabel)
- IOS UILabel
- IOS-UILabel
- IOS UIlabel
- IOS UILabel
- iOS UILabel
- IOS UILabel
- IOS UILabel
- iOS组件之UILabel
- UILabel-IOS开发
- IOS控件UILabel总结
- IOS--UILabel 用法详解
- IOS#UI之UIlabel
- iOS UILabel 自适应
- ios:定制UILabel
- Java Socket应用(六)——服务器响应客户端
- int 最大最小范围
- Linux基本命令1
- IOS--C 语言 Lesson Eight Struct
- Stanford机器学习---第十一讲.异常检测
- iOS UILabel
- shopnc b2b2c初次运行提示Class Error: mysqli.isn't exists!的解决方法
- zoj2412
- 黑马程序员---2015.6.26java基础笔记--File类--Properties--PrintStream--SequenceInputStream--RandomAccessFile
- WebView控件应用——模仿URL有道词典
- 为什么使用portlet?
- 金士顿KTD-INSP6000C/2G内存
- iOS-学习笔记-UI-第十九天
- 在Android APK中调用底层linux命令或者脚本