objective-c – UIButton中的多行

前端之家收集整理的这篇文章主要介绍了objective-c – UIButton中的多行前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
嗨,我的问题是设置多个行到我的按钮,这被声明为:
  1. button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
  2. button.titleLabel.font = [UIFont systemFontOfSize: 12];
  3. button.titleLabel.lineBreakMode = UILineBreakModeWordWrap;
  4. button.titleLabel.numberOfLines = 0;
  5. button.titleLabel.shadowOffset = CGSizeMake (1.0,0.0);
  6.  
  7. [button addTarget:self
  8. action:@selector(myButtonClick)
  9. forControlEvents:UIControlEventTouchDown];
  10.  
  11. button.frame = CGRectMake(0.0,100.0,317.0,100.0);
  12. [button setTitle:string forState:UIControlStateNormal];
  13. button.titleLabel.font = [UIFont systemFontOfSize: 12];
  14. button.titleLabel.text = @"ahoj";
  15.  
  16. NSMutableString *ObratString = [[NSMutableString alloc] initWithString:button.titleLabel.text];
  17.  
  18. [ObratString appendString:@"\n"];
  19. [ObratString appendString:@"caw"];
  20. [ObratString appendString:@"\n"];
  21. [ObratString appendString:@"helllo"];
  22. button.titleLabel.text = ObratString;
  23. [ObratString release];
  24. [self.view addSubview:button];

但最后我只看到第一行.
有什么办法让它工作吗?

解决方法

UIButton显示包含UILabel的文本.包含的标签的默认值仅显示一行文本.该标签可通过titleLabel属性访问,任何可以对正常标签执行的操作都可以完成.

例如使用多行的方式打破字:

  1. myButton.titleLabel. numberOfLines = 0; // Dynamic number of lines
  2. myButton.titleLabel.lineBreakMode = UILineBreakModeWordWrap;

猜你在找的C&C++相关文章