How to left-justify the title of UIActionSheet

2019-07-30 23:52发布

问题:

Is it possible to left-justify the title text of a UIActionSheet? Thanks!

回答1:

It is not possible to customize the title of an UIActionSheet. If you want something similar, you will have to design your own clone.



回答2:

You can simply use spaces after the name that you set for a button in UIActionsheet. For example if it is @"download" you can change to @"Download------------" which dashes here are spaces.

I hope it works.



回答3:

yes, you can do it.

NSArray *subViewArray = yourActionSheet.subviews;
for(int x=0;x<[subViewArray count];x++){
    if([[[subViewArray objectAtIndex:x] class] isSubclassOfClass:[UILabel class]])
    {
        UILabel *label = [subViewArray objectAtIndex:x];
        label.textAlignment = NSTextAlignmentLeft;
    }

}


回答4:

Yes it is possible

- (void)willPresentActionSheet:(UIActionSheet *)actionSheet {
    [actionSheet.subviews enumerateObjectsUsingBlock:^(id _currentView, NSUInteger idx, BOOL *stop) {
        if ([_currentView isKindOfClass:[UIButton class]]) {
            ((UIButton *)_currentView).contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
            ((UIButton *)_currentView).contentEdgeInsets = UIEdgeInsetsMake(0, 30, 0, 0);
        }
    }];
}