Change font type and size of UIActionSheet title string

后端 未结 6 747
误落风尘
误落风尘 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:09

    For iOS 7 the following code will work.

    Implement UIActionSheetDelegate as follows

    - (void)willPresentActionSheet:(UIActionSheet *)actionSheet {
        [actionSheet.subviews enumerateObjectsUsingBlock:^(id _currentView, NSUInteger idx, BOOL *stop) {
            if ([_currentView isKindOfClass:[UIButton class]]) {
                [((UIButton *)_currentView).titleLabel setFont:[UIFont boldSystemFontOfSize:15.f]];
                // OR
                //[((UIButton *)_currentView).titleLabel setFont:[UIFont fontWithName:@"Exo2-SemiBold" size:17]];
            }
        }];
    }
    

    For iOS 6

    - (void)willPresentActionSheet:(UIActionSheet *)actionSheet {
        for (UIView *_currentView in actionSheet.subviews) {
            if ([_currentView isKindOfClass:[UILabel class]]) {
                [(UILabel *)_currentView setFont:[UIFont boldSystemFontOfSize:15.f]];
                // OR
                //[(UILabel *)_currentView setFont:[UIFont fontWithName:@"Exo2-SemiBold" size:17]];
            }
        }
    }
    

提交回复
热议问题