iOS >> UIButton ImageView Property >> How to set Content Mode?

后端 未结 3 540
北荒
北荒 2020-12-29 12:05

Is there a way to set a UIButton Image, BackgroundImage or ImageView Properties Content Mode Property?

I\'ve tried the direct approach (it didn\'t work, of course...

3条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-29 12:28

    if you don't want to subclass UIButton than you can try this,

        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        for (UIView *view in button.subviews) {
            if ([view isKindOfClass:[UIImageView class]]) {
                [view setContentMode:UIViewContentModeScaleAspectFit];
            }
        }
    

提交回复
热议问题