Pages

Wednesday, January 18, 2012

How to change of default title font in the UIActionSheet?

There is no direct way to access the UIActionSheet’s default title properties. There are couple of ways you can do this.
One is, to customize the UIActionSheet.
Second is, to add the label as the sub-view to the UIActionSheet, and set the default title to be nil. But if you do this, there are some other changes apart from adding the label as title. You need to set the frame of the buttons (of type ‘UIThirdPartButton’) inside the UIActionSheet. The code looks like something as follows:
UILabel *titleLabel =
[[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 50.0)];
titleLabel.font = [UIFont boldSystemFontOfSize:16.0];
titleLabel.textAlignment = UITextAlignmentCenter;
titleLabel.backgroundColor = [UIColor clearColor];
titleLabel.textColor = [UIColor whiteColor];
titleLabel.text = k3PPTitle;
[actionSheet addSubview:titleLabel];
[titleLabel release];
actionSheet.actionSheetStyle = UIActionSheetStyleDefault;
[actionSheet showInView:self.view];
CGRect actionSheetRect = actionSheet.frame;
actionSheetRect.origin.y -= 40.0;
actionSheetRect.size.height = 300.0;
actionSheet.frame = actionSheetRect;
for (int counter = 0; counter < [[actionSheet subviews] count]; counter++) {
    UIView *object = [[actionSheet subviews] objectAtIndex:counter];
    if ([object class] == NSClassFromString(@”UIThreePartButton”)) {
        CGRect frame = object.frame;
        frame.origin.y = frame.origin.y + 30.0;
        object.frame = frame;
    }
}

No comments:

Post a Comment