IOS UILabel组件
生活随笔
收集整理的這篇文章主要介紹了
IOS UILabel组件
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
UILabel 是 IOS 顯示文字的組件,繼承與UIView
屬性
| text | @property(nullable, nonatomic,copy) NSString | 文字 | nil |
| font | @property(null_resettable, nonatomic,strong) UIFont | 字體大小 | 17 |
| textColor | @property(null_resettable, nonatomic,strong) UIColor | 字體顏色| blackColor | |
| shadowColor | @property(nullable, nonatomic,strong) UIColor | 陰影顏色 | nil |
| textAlignment | @property(nonatomic) NSTextAlignment | 字體方向 | 默認為 NSTextAlignmentNatural IOS9之前為 NSTextAlignmentNatural |
| lineBreakMode | @property(nonatomic) NSLineBreakMode | 換行模式 | 默認為NSLineBreakByTruncatingTail. 可用于多行和單行。 |
| attributedText | @property(nullable, nonatomic,copy) NSAttributedString * | 富文本內容,設置了此屬性將不顯示text屬性。 | nil |
| enabled | @property(nonatomic,getter=isEnabled) BOOL | 是否顯示 | YES |
| numberOfLines | @property(nonatomic) NSInteger | 最多可顯示的行數,0表示無限行數 | 1 |
| adjustsFontSizeToFitWidth | @property(nonatomic) BOOL | 是否根據字體大小調整寬度 | NO |
| baselineAdjustment | @property(nonatomic) UIBaselineAdjustment | 字體基線 | UIBaselineAdjustmentAlignBaselines |
| allowsDefaultTighteningForTruncation | @property(nonatomic) BOOL | 是否允許截斷 | NO |
簡單代碼
@implementation ViewController- (void)viewDidLoad {[super viewDidLoad];// Do any additional setup after loading the view.[self createLableUI];[self createSuperLabelUI]; }// LabelUI - (void)createLableUI {UILabel *label = [[UILabel alloc] init];label.text = @"hello wrod";// 設置坐標label.frame = CGRectMake(100, 100, 200, 50);// 設置背景透明顏色 clearColorlabel.backgroundColor = [UIColor clearColor];// 設置文字顏色label.textColor = [UIColor redColor];// 設置字體大小label.font = [UIFont systemFontOfSize: 40];// 設置陰影label.shadowColor = [UIColor redColor];// 設置陰影偏移量label.shadowOffset = CGSizeMake(2, 2);// 設置文字方向label.textAlignment = NSTextAlignmentCenter;// 設置文字最多行數,默認1行label.numberOfLines = 2;// 添加視圖[self.view addSubview:label]; }- (void)createSuperLabelUI {UILabel *superLabel = [[UILabel alloc] init];superLabel.frame = CGRectMake(100, 300, 200, 400);superLabel.numberOfLines = 0;NSString *str = @"Im\nSuper\nLabel";NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString:str];superLabel.attributedText = text;[self.view addSubview:superLabel]; } @end總結
以上是生活随笔為你收集整理的IOS UILabel组件的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java 线程 事件_Java事件调度线
- 下一篇: IOS 模态弹窗与操作版使用 UIAle