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
There is an internal property of UIActionSheet
called _titleLabel
so it is possible to get a reference and change the attributed string property of this label directly.
Please be aware, that this is a private API in might be rejected in the App store.
Here is how it works:
- (NSAttributedString *) actionSheetAttributedTitle;
{
NSMutableAttributedString *attString=[[NSMutableAttributedString alloc] initWithString:@"Test"];
UIFont *font=[UIFont fontWithName:@"Helvetica-Bold" size:13.0f];
[attString addAttribute:NSFontAttributeName value:font range:NSMakeRange(0, attString.length)];
[attString addAttribute:NSForegroundColorAttributeName
value:[UIColor blackColor]
range:NSMakeRange(0, attString.length)];
return [attString copy];
}
- (void)willPresentActionSheet:(UIActionSheet *)actionSheet;
{
UILabel *sheetTitleLabel;
if([actionSheet respondsToSelector:@selector(_titleLabel)]) {
sheetTitleLabel = objc_msgSend(actionSheet, @selector(_titleLabel));
sheetTitleLabel.attributedText = [self actionSheetAttributedTitle];
}
}