Change font type and size of UIActionSheet title string

后端 未结 6 869
误落风尘
误落风尘 2021-02-06 05:29

I have a UIActionSheet with title string \"DO: These tasks\". In the title string, the substring \"DO:\" should be Bold(with a particular font size) and the substring \"These ta

6条回答
  •  执笔经年
    2021-02-06 06:21

    Based on Holex's answer:

    for both iOS7 and iOS6 the following has worked for me to change the title of UIActionSheet properties. Please note that I am actually adding a new subview, since for unknown? reason updating the current UILabel gives only vertically half of the text? Also "title" is apparantly the first UILabel, so we break the loop after one change.

    - (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;
            }
        }
    }
    

    The above seems to work on iOS6 and iOS7 simulators. I am not sure if this would work with other future versions of iOS though.

提交回复
热议问题