Objective c 将字体大小设置为UIActionSheet标题
我需要设置大小UIActionSheet标题“选择要复制的选项” 使用此代码:Objective c 将字体大小设置为UIActionSheet标题,objective-c,uiactionsheet,Objective C,Uiactionsheet,我需要设置大小UIActionSheet标题“选择要复制的选项” 使用此代码: [[UIActionSheet alloc] initWithTitle:@"Select option to copy:" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"copy all ",nil];
[[UIActionSheet alloc] initWithTitle:@"Select option to copy:" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil
otherButtonTitles:@"copy all ",nil];
您可以使用此delgate更改
uiactionsheet
的标题字体
-(void)willPresentActionSheet:(UIActionSheet *)actionSheet {
for (UIView *_currentView in actionSheet.subviews) {
if ([_currentView isKindOfClass:[UILabel class]]) {
UILabel *l = [[UILabel alloc] initWithFrame:_currentView.frame];
l.text = [(UILabel *)_currentView text];
[l setFont:[UIFont fontWithName:@"Arial-BoldMT" size:20]];
l.textColor = [UIColor darkGrayColor];
l.backgroundColor = [UIColor clearColor];
[l sizeToFit];
[l setCenter:CGPointMake(actionSheet.center.x, 25)];
[l setFrame:CGRectIntegral(l.frame)];
[actionSheet addSubview:l];
_currentView.hidden = YES;
break;
}
}
}
您可以利用运行时属性设置字体。通过使用
NSAttributedString
可以实现这一点
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil
otherButtonTitles:@"copy all ",nil];
//Creating Attributed String with System Font size of 30.0f
NSAttributedString *attrString = [[NSAttributedString alloc] initWithString:@"Select option to copy:" attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:30.0f]}];
//Accessing the Alert View Controller property from Action Sheet
UIAlertController *alertController = [actionSheet valueForKey:@"_alertController"];
//Setting Attributed Title property of Alert View Controller
[alertController setValue:attrString forKey:@"_attributedTitle"];
//Displaying the Action Sheet
[actionSheet showInView:self.view];
你试过什么?您是如何创建此行动表的?给我们看一些代码;)它仍然不会改变尺寸);我添加了一个问题:ios版本是7还是8?视图层次结构确实已经改变了,在ios 8或更高版本中,您不应该再使用UIActionSheet。UIActionSheet已弃用。将UIAlertController与首选样式UIAlertControllerStyleActionSheet一起使用“如何更改蓝色按钮的字体大小?@RoeiNadam在actionsheet中没有API来修改操作按钮的字体。话虽如此,我想看看是否有人能想出解决方案。好的,它包括按钮标题的颜色?您可以通过设置ActionSheet的
tintColor
属性来更改颜色,或者如果您希望每个按钮都有不同的颜色,则使用UIAlertViewController
。对于每个UIAlertAction
,都有一个名为\u titleTextColor
的运行时属性。使用此属性可以更改每个项目的颜色