这是我的代码
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Added to Cart" message:@"Some items are added for time being!" delegate:self cancelButtonTitle:@"View Cart" otherButtonTitles:@"Continue \n Shopping", nil];
alert.tag = 20;
[alert show];
答案 0 :(得分:2)
我有手动解决方案。但我认为这不是一个好的解决方案:
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Added to Cart" message:@"Some items are added for time being!" delegate:self cancelButtonTitle:@"View Cart" otherButtonTitles:@"", nil];
UILabel *buttonTitle = [[UILabel alloc] initWithFrame:CGRectMake(148, 102, 125, 40)];
buttonTitle.text = @"Continue Shopping";
buttonTitle.font = [UIFont boldSystemFontOfSize:15];
buttonTitle.textColor = [UIColor whiteColor];
buttonTitle.textAlignment = UITextAlignmentCenter;
buttonTitle.backgroundColor = [UIColor clearColor];
buttonTitle.numberOfLines = 2;
[alert addSubview:buttonTitle];
alert.tag = 20;
[buttonTitle release];
[alert show];
无论如何你都可以使用它......
答案 1 :(得分:1)
UIAlertView
不支持多行按钮。一种选择是仅使用“继续”而不是“继续购物”作为按钮标题,否则您必须使用自定义警报视图组件,例如, CODialog(您可能需要稍微自定义它以允许多行按钮,但它应该很容易)。
答案 2 :(得分:0)
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Added to Cart" message:@"Some items are added for time being!" delegate:self cancelButtonTitle:@"View Cart" otherButtonTitles:@"Continue \n Shopping", nil];
alert.tag = 20;
[[[alert buttons] objectAtIndex:1] setLineBreakMode:UILineBreakModeWordWrap];
[alert show];
此代码完全符合您的需要。 但请注意
- [UIAlertView buttons]
未记录 - [UIButton setLineBreakMode]
已弃用。但是,您可以用
[button.titleLabel setLineBreakMode]
基本相同。
答案 3 :(得分:0)
我认为您可以尝试将numbersOfLine属性设置为按钮上的标签。但我不知道苹果会否认这一点。
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Added to Cart" message:@"Some items are added for time being!" delegate:self cancelButtonTitle:@"View Cart" otherButtonTitles:@"Continue \n Shopping", nil];
NSArray *subviewsArray = [alert subviews];
for (UIView *subview in subviewsArray) {
if ([subview isKindOfClass:[UIButton class]]) {
NSArray *btnSubviews = [subview subviews];
for (UIView *btnSubview in btnSubviews) {
if ([btnSubview isKindOfClass:[UILabel class]]) {
UILabel *title = (UILabel *)btnSubview;
title.numberOfLines = 2;
}
}
}
}
alert.tag = 20;
[alert show];
[alert release];