日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

IOS UILabel组件

發布時間:2025/3/12 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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组件的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。