iPhone UIButton - image position

前端 未结 16 587
梦谈多话
梦谈多话 2020-12-04 06:18

I have a UIButton with text \"Explore the app\" and UIImage (>) In Interface Builder it looks like:

[ (>) Explore t         


        
16条回答
  •  情深已故
    2020-12-04 06:50

    Raymond W's answer is best here. Subclass UIButton with custom layoutSubviews. Extremely simple to do, here's a layoutSubviews implementation that worked for me:

    - (void)layoutSubviews
    {
        // Allow default layout, then adjust image and label positions
        [super layoutSubviews];
    
        UIImageView *imageView = [self imageView];
        UILabel *label = [self titleLabel];
    
        CGRect imageFrame = imageView.frame;
        CGRect labelFrame = label.frame;
    
        labelFrame.origin.x = imageFrame.origin.x;
        imageFrame.origin.x = labelFrame.origin.x + CGRectGetWidth(labelFrame);
    
        imageView.frame = imageFrame;
        label.frame = labelFrame;
    }
    

提交回复
热议问题