iOS UILabel、UIButton文字豎排顯示
- (void)viewDidLoad {
[superviewDidLoad];
方法一:
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 100, 25,200)];
label.text = @"即\n時\n編\n譯\n功\n能\n。";
label.numberOfLines = [label.text length];
[self.view addSubview:label];
方法二:
UIFont *font = [UIFont systemFontOfSize
CGSize sizeWord = [@"一"sizeWithFont:font constrainedToSize:CGSizeMake(100, 1000.0) lineBreakMode:UILineBreakModeWordWrap];
CGFloat width = sizeWord.width;//一個漢字的寬度
CGSize sizeStr = [@"是一個小巧的指令碼語言。"sizeWithFont:font constrainedToSize:CGSizeMake(width, 1000.0) lineBreakMode:UILineBreakModeWordWrap];
CGFloat hight = sizeStr.height;
UILabel *labelTwo = [[UILabel alloc]initWithFrame:CGRectMake(50, 200, width, hight)];
labelTwo.text = @"是一個小巧的指令碼語言。";
labelTwo.textColor = [UIColor blackColor];
labelTwo.numberOfLines = 0;
[self.view addSubview:labelTwo];
UIButton *button=[[UIButton
button.titleLabel.font=[UIFont fontWithName:@"Helvetica" size:24];
[button setTitle:@"其設計目的是為了嵌入應用程式中"forState:UIControlStateNormal];
[button setTitleColor:[UIColorblackColor] forState:UIControlStateNormal];
[button setTitleColor:[UIColorredColor] forState:UIControlStateHighlighted];
button.titleLabel.lineBreakMode = UILineBreakModeWordWrap;//換行模式自動換行
button.titleLabel.numberOfLines = 0;
[self.view addSubview:button];
}