UIActionSheet button text not displaying properly in ios 8

不问归期 提交于 2019-12-11 22:18:59

问题


I am trying to create little custome UI of UIActionSheet.I want to display the large text in button of UIActionSheet. This code is working fine below ios 8, But in ios 8 - (void)willPresentActionSheet:(UIActionSheet *)actionSheet {

for (UIView *subview in actionSheet.subviews) {
    if ([subview isKindOfClass:[UIButton class]]) {
        UIButton *button = (UIButton *)subview;
        UIFont *textFont=[UIFont fontWithName:@"Palatino-Roman" size:12.0];
        button.titleLabel.font=textFont;
        button.titleLabel.numberOfLines=4;
        [button setContentHorizontalAlignment:UIControlContentVerticalAlignmentCenter];

        constrainedToSize:constraint1 lineBreakMode:NSLineBreakByWordWrapping];
        [button setFrame:CGRectMake(button.frame.origin.x+4,button.frame.origin.y+2,button.frame.size.width-4, button.frame.size.height)];

        if([[UIDevice currentDevice] systemVersion].floatValue<=5.0)
        {
            button.titleLabel.lineBreakMode = UILineBreakModeWordWrap;
            button.titleLabel.textAlignment = UITextAlignmentCenter;
        }
        else
        {
            button.titleLabel.lineBreakMode = NSLineBreakByWordWrapping;
            button.titleLabel.textAlignment = NSTextAlignmentCenter;
        }

    }
}

}


回答1:


UIActionSheet is deprecated in iOS 8 so please use UIAlertController

check this link https://developer.apple.com/library/ios/documentation/Uikit/reference/UIActionSheet_Class/index.html

https://developer.apple.com/library/ios/documentation/Uikit/reference/UIAlertController_class/index.html#//apple_ref/c/econst/UIAlertControllerStyleActionSheet



来源:https://stackoverflow.com/questions/26277614/uiactionsheet-button-text-not-displaying-properly-in-ios-8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!