label的基本属性
1. numberOfLines: 设置Label文本显示的行数,如果设置的行数大于Label的宽度,以Label的宽度为准显示文本。
2. adjustsFontSizeToFitWidth: 自动调整字体的大小适用Label的大小。
3. enabled, 默认设置是YES,如果设置为NO,label变为不活跃状态,不可以更改字体颜色。
4. transform, 是一个CGAffineTransform类型,可以对Label进行移动,旋转,缩放等操作,如对Label进行旋转:CGAffineTransformMakeRotation(0.5),参数为旋转的角度。
5. baselineAdjustment: 只有当numberOfLines = 1时,这个属性生效,baselineAdjustment为枚举类型属性,枚举值分别为:
UIBaselineAdjustmentAlignBaselines, // Label需要显示的文本下边界与Label的中心线对齐
UIBaselineAdjustmentAlignCenters, // Label文本的中心线与Label的中心线对齐。
UIBaselineAdjustmentNone, // Label需要显示的文本上边界与Label的中心线对齐
6. miniumScaleFactor: 设置Label文本显示的最小字体。
7. lineBreakMode: Label文本的换行模式,lineBreakMode为枚举值,是枚举类型属性,枚举值分别为:
UILineBreakModeWordWrap = 0, // 以单词为单位换行,以单位为单位截断。
UILineBreakModeCharacterWrap, // 以字符为单位换行,以字符为单位截断。
UILineBreakModeClip, // 以单词为单位换行。以字符为单位截断。
UILineBreakModeHeadTruncation, // 以单词为单位换行,如果是单行,则开始部分有省略号, 。
UILineBreakModeTailTruncation, // 以单词为单位换行,末尾有省略号。
UILineBreakModeMiddleTruncation, // 以单词为单位换行,中间有省略号。
8. highlighted, highlightedColor, 一般组合使用,改变高亮时字体颜色。
9. textAlignment: 设置Label 文本的对齐方式,是枚举类型属性,枚举值分别为:
NSTextAlignmentLeft = 0, // 文本左对齐
NSTextAlignmentCenter = 1, // 文本居中对齐
NSTextAlignmentRight = 2, // 文本右对齐
NSTextAlignmentJustified = 3, // 文本两端对齐
NSTextAlignmentNatural = 4, // 自然文本对齐
10. attributedText.自定义label文本的显示方式,是NSAttributedString的属性。使用NSAttributedString需要导入框架CoreText.framework,引入头文件 #import <CoreText/CoreText.h>,
如创建一个NSMutableAttributedString对象 attribute, 为attribute添加属性。
NSMutableAttributedString *attribute = [[NSMutableAttributedString alloc] initWithString:@"Hello world."];
//给Hello加上下划线,value可以在指定的枚举中选择
[attribute addAttribute:(NSString *)kCTUnderlineStyleAttributeNamevalue:(id)[NSNumber numberWithInt:kCTUnderlineStyleDouble]range:NSMakeRange(0, 5)];
// 指定Label的attributedText属性为attribute
label.attributedText = attribute;
imageView的基本属性
1.Image 设置图片,默认显示 UIImageView *_imageView = [[ UIImageView alloc ] init ]; _imageView . image = [ UIImage imageNamed : @"me.png" ]; 2.highlightedImage 设置高亮状态下显示的图片 _imageView.highlighted = yes; _imageView . highlightedImage = [ UIImage imageNamed : @"other.png" ]; 3.animationImages 设置序列帧动画的图片数组 [ _imageView setAnimationImages :[ NSArray array ]]; 4.highlightedAnimationImages 设置高亮状态下序列帧动画的图片数组 [ _imageView setHighlightedAnimationImages :[ NSArray array ]]; 5.animationDuration 设置序列帧动画播放的时常 [ _imageView setAnimationDuration : 0.3f ]; 6.animationRepeatCount 设置序列帧动画播放的次数 [ _imageView setAnimationRepeatCount : 2 ]; 7.userInteractionEnabled 设置是否允许用户交互,默认不允许用户交互 [ _imageView setUserInteractionEnabled : YES ]; 8.highlighted 设置是否为高亮状态,默认为普通状态 _imageView . highlightedImage = [ UIImage imageNamed : @"other.png" ]; [ _imageView setHighlighted : YES ]; 注意的是在 highlighted 状态下设置的图片与序列帧动画要显示,必须同时设置 UIImageView 的状态为 highlighted 。
1. numberOfLines: 设置Label文本显示的行数,如果设置的行数大于Label的宽度,以Label的宽度为准显示文本。
2. adjustsFontSizeToFitWidth: 自动调整字体的大小适用Label的大小。
3. enabled, 默认设置是YES,如果设置为NO,label变为不活跃状态,不可以更改字体颜色。
4. transform, 是一个CGAffineTransform类型,可以对Label进行移动,旋转,缩放等操作,如对Label进行旋转:CGAffineTransformMakeRotation(0.5),参数为旋转的角度。
5. baselineAdjustment: 只有当numberOfLines = 1时,这个属性生效,baselineAdjustment为枚举类型属性,枚举值分别为:
UIBaselineAdjustmentAlignBaselines, // Label需要显示的文本下边界与Label的中心线对齐
UIBaselineAdjustmentAlignCenters, // Label文本的中心线与Label的中心线对齐。
UIBaselineAdjustmentNone, // Label需要显示的文本上边界与Label的中心线对齐
6. miniumScaleFactor: 设置Label文本显示的最小字体。
7. lineBreakMode: Label文本的换行模式,lineBreakMode为枚举值,是枚举类型属性,枚举值分别为:
UILineBreakModeWordWrap = 0, // 以单词为单位换行,以单位为单位截断。
UILineBreakModeCharacterWrap, // 以字符为单位换行,以字符为单位截断。
UILineBreakModeClip, // 以单词为单位换行。以字符为单位截断。
UILineBreakModeHeadTruncation, // 以单词为单位换行,如果是单行,则开始部分有省略号, 。
UILineBreakModeTailTruncation, // 以单词为单位换行,末尾有省略号。
UILineBreakModeMiddleTruncation, // 以单词为单位换行,中间有省略号。
8. highlighted, highlightedColor, 一般组合使用,改变高亮时字体颜色。
9. textAlignment: 设置Label 文本的对齐方式,是枚举类型属性,枚举值分别为:
NSTextAlignmentLeft = 0, // 文本左对齐
NSTextAlignmentCenter = 1, // 文本居中对齐
NSTextAlignmentRight = 2, // 文本右对齐
NSTextAlignmentJustified = 3, // 文本两端对齐
NSTextAlignmentNatural = 4, // 自然文本对齐
10. attributedText.自定义label文本的显示方式,是NSAttributedString的属性。使用NSAttributedString需要导入框架CoreText.framework,引入头文件 #import <CoreText/CoreText.h>,
如创建一个NSMutableAttributedString对象 attribute, 为attribute添加属性。
NSMutableAttributedString *attribute = [[NSMutableAttributedString alloc] initWithString:@"Hello world."];
//给Hello加上下划线,value可以在指定的枚举中选择
[attribute addAttribute:(NSString *)kCTUnderlineStyleAttributeNamevalue:(id)[NSNumber numberWithInt:kCTUnderlineStyleDouble]range:NSMakeRange(0, 5)];
// 指定Label的attributedText属性为attribute
label.attributedText = attribute;
imageView的基本属性
1.Image 设置图片,默认显示 UIImageView *_imageView = [[ UIImageView alloc ] init ]; _imageView . image = [ UIImage imageNamed : @"me.png" ]; 2.highlightedImage 设置高亮状态下显示的图片 _imageView.highlighted = yes; _imageView . highlightedImage = [ UIImage imageNamed : @"other.png" ]; 3.animationImages 设置序列帧动画的图片数组 [ _imageView setAnimationImages :[ NSArray array ]]; 4.highlightedAnimationImages 设置高亮状态下序列帧动画的图片数组 [ _imageView setHighlightedAnimationImages :[ NSArray array ]]; 5.animationDuration 设置序列帧动画播放的时常 [ _imageView setAnimationDuration : 0.3f ]; 6.animationRepeatCount 设置序列帧动画播放的次数 [ _imageView setAnimationRepeatCount : 2 ]; 7.userInteractionEnabled 设置是否允许用户交互,默认不允许用户交互 [ _imageView setUserInteractionEnabled : YES ]; 8.highlighted 设置是否为高亮状态,默认为普通状态 _imageView . highlightedImage = [ UIImage imageNamed : @"other.png" ]; [ _imageView setHighlighted : YES ]; 注意的是在 highlighted 状态下设置的图片与序列帧动画要显示,必须同时设置 UIImageView 的状态为 highlighted 。