//建立一個Lable _beemer = [[UILabel alloc]initWithFrame:CGRectMake(0*RATIO, 445*RATIO, _bidBgImgView.bounds.size.width, 50*RATIO)];//初始化 _beemer.text = @"Jet";//能夠無視 _beemer.textColor = [UIColor whiteColor];//設置Labe裏面的字體顏色 _beemer.textAlignment = NSTextAlignmentCenter;//文字居中顯示 _beemer.numberOfLines = 0;//自動換行 REGULAR_OBJ(_beemer, 20*RATIO);//宏定義設置文字字體和大小。 [_bidBgImgView addSubview:_beemer]; NSString *str = [NSString stringWithFormat:@"%@ at",_infoModels.ContactPerson];//動態獲取值 //富文本 //把動態獲取到的值傳給富文本AttributedStr。 NSMutableAttributedString *AttributedStr = [[NSMutableAttributedString alloc]initWithString:str]; //第一個參數addAttribute說明在下面有說明,第二個參數value設置改變Lable的字體和大小,第三個參數range是修改Lable文字的範圍。 [AttributedStr addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"HelveticaLTStd-Bold" size:20*RATIO] range:NSMakeRange(0, _infoModels.ContactPerson.length)]; _beemer.attributedText = AttributedStr;
常見的屬性及說明字體
NSFontAttributeName 字體 NSParagraphStyleAttributeName 段落格式 NSForegroundColorAttributeName 字體顏色 NSBackgroundColorAttributeName 背景顏色 NSStrikethroughStyleAttributeName 刪除線格式 NSUnderlineStyleAttributeName 下劃線格式 NSStrokeColorAttributeName 刪除線顏色 NSStrokeWidthAttributeName 刪除線寬度 NSShadowAttributeName 陰影