嗨,我的问题是设置多个行到我的按钮,这被声明为:
button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.titleLabel.font = [UIFont systemFontOfSize: 12];
button.titleLabel.lineBreakMode = UILineBreakModeWordWrap;
button.titleLabel.numberOfLines = 0;
button.titleLabel.shadowOffset = CGSizeMake (1.0,0.0);
[button addTarget:self
action:@selector(myButtonClick)
forControlEvents:UIControlEventTouchDown];
button.frame = CGRectMake(0.0,100.0,317.0,100.0);
[button setTitle:string forState:UIControlStatenormal];
button.titleLabel.font = [UIFont systemFontOfSize: 12];
button.titleLabel.text = @"ahoj";
NSMutableString *ObratString = [[NSMutableString alloc] initWithString:button.titleLabel.text];
[ObratString appendString:@"\n"];
[ObratString appendString:@"caw"];
[ObratString appendString:@"\n"];
[ObratString appendString:@"helllo"];
button.titleLabel.text = ObratString;
[ObratString release];
[self.view addSubview:button];
但最后我只看到第一行.
有什么办法让它工作吗?
解决方法
UIButton显示包含UILabel的文本.包含的标签的默认值仅显示一行文本.该标签可通过titleLabel属性访问,任何可以对正常标签执行的操作都可以完成.
例如使用多行的方式打破字:
myButton.titleLabel. numberOfLines = 0; // Dynamic number of lines myButton.titleLabel.lineBreakMode = UILineBreakModeWordWrap;