Label under image in UIButton

后端 未结 30 2066
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-29 15:53

I\'m trying to create a button which has some text beneath the icon (sorta like the app buttons) however it seems to be quite difficult to achieve. Any ideas how can I go ab

30条回答
  •  被撕碎了的回忆
    2020-11-29 16:39

    Subclass UIButton. Override -layoutSubviews to move the built-in subviews into new positions:

    - (void)layoutSubviews
    {
        [super layoutSubviews];
    
        CGRect frame = self.imageView.frame;
        frame = CGRectMake(truncf((self.bounds.size.width - frame.size.width) / 2), 0.0f, frame.size.width, frame.size.height);
        self.imageView.frame = frame;
    
        frame = self.titleLabel.frame;
        frame = CGRectMake(truncf((self.bounds.size.width - frame.size.width) / 2), self.bounds.size.height - frame.size.height, frame.size.width, frame.size.height);
        self.titleLabel.frame = frame;
    }
    

提交回复
热议问题