0
我要標籤文本排列在標籤文本行的方形視圖格式上,標籤有一些短詞,有些是比其他詞標籤文字更大的尺寸,所以請看這個演示圖片Sqaure shape ImageUILabel文本行設置爲方形排列iOS
我要標籤文本排列在標籤文本行的方形視圖格式上,標籤有一些短詞,有些是比其他詞標籤文字更大的尺寸,所以請看這個演示圖片Sqaure shape ImageUILabel文本行設置爲方形排列iOS
嘗試使用NSAttributedString希望支持多種字體和文本大小,並使用\ n返回到下一行。
NSDictionary *italicAttrs = @{NSFontAttributeName : [UIFont fontWithName:@"HelveticaNeue-Bold" size:16], NSForegroundColorAttributeName : [UIColor colorWithRed:0.0 green:122.0/255.0 blue:1.0 alpha:1.0]};
NSDictionary *defaultAttrs = @{NSFontAttributeName : [UIFont fontWithName:@"HelveticaNeue-Medium" size:16], NSForegroundColorAttributeName : [UIColor blackColor]};
NSDictionary *arrowAttrs = @{NSFontAttributeName : [UIFont fontWithName:@"AlNile-Bold" size:20], NSForegroundColorAttributeName : [UIColor grayColor]};
NSMutableAttributedString *labelText = [[NSMutableAttributedString alloc] init];
NSAttributedString *from = [[NSAttributedString alloc] initWithString:@"From: " attributes:italicAttrs];
NSAttributedString *content = [[NSAttributedString alloc] initWithString:@"Me\n" attributes:defaultAttrs];
NSAttributedString *arrow = [[NSAttributedString alloc] initWithString:@"Ok" attributes:arrowAttrs];
[labelText appendAttributedString:from];
[labelText appendAttributedString:content];
[labelText appendAttributedString:arrow];
是的它使用NSMutableAttributedString但使多個字體和文本大小。我想製作隨機字體大小和字體文本大小,而不是固定的文本長度,其文本長度是動態的,以提示我 – Keyur
你想要做的是繪製一個這樣的圖像,然後將圖像加載到按鈕上。 –
[鏈接](http://i.stack.imgur.com/foDPR.png)@pRiva請點擊此鏈接演示圖片 – Keyur
標籤只有1個字體。擁有多個字體需要多個標籤。它不可能像使用標籤的演示製作UI一樣。 U可以繪製圖像並在UIImage上添加圖像。如果你的意思是你想排序你的標籤,你可以使用堆棧視圖並使用一些約束。如果這就是你想要的,我可以幫你。 –