Button设置内部的控件位置

如下图:
Button设置内部的控件位置_第1张图片

 UIButton *leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    leftBtn.frame = CGRectMake(0, 0, 40, 35);
    //<* button的的图片和文字居中 *>
    leftBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    //<* 设置title的向左偏移35 *>
    [leftBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, -35, 0, 0)];
    [leftBtn setImage:[UIImage imageNamed:@"icon_homepage_downArrow"] forState:UIControlStateNormal];
    leftBtn.imageEdgeInsets = UIEdgeInsetsMake(0, 30, 0, 0);
    [leftBtn setTitle:@"上海" forState:UIControlStateNormal];
NSTextAlignmentLeft;
    leftBtn.titleLabel.font = kFONT10;

你可能感兴趣的:(Button设置内部的控件位置)