[btn setImage:imgNor forState:UIControlStateNormal]; [btn setImage:imgSel forState:UIControlStateSelected]; [btn setTitle:[arrLabel objectAtIndex:i] forState:UIControlStateNormal]; [btn setTitleColor:kCOLOR_TABBARNOR forState:UIControlStateNormal]; [btn setTitleColor:kCOLOR_TABBARSEL forState:UIControlStateSelected]; //设置控件的排列方式 为 左上 ,否则默认是中中 btn.contentVerticalAlignment = UIControlContentVerticalAlignmentTop; btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; btn.titleLabel.font = KFONT(kTEXT_SIZE_MINI); //(上top,左left,下bottom,右right) //设置 title的偏移量 图片的偏移量+图片的高+(剩余空间-文字高度)/2 。下居中显示文字 左偏移量:(控件的宽度-文字的宽度)/2-图片的宽度。 这里很重要,为什么还要减去图片的宽度呢??因为 默认的图片文字排列 是 图片在左,文字紧跟图片,即文字在图片的右边。这里减去图片的宽度。 bt.titleEdgeInsets = UIEdgeInsetsMake((bt.imageEdgeInsets.top+image_sel.size.height)+(bt.frame.size.height-(bt.imageEdgeInsets.top+image_sel.size.height)-size.height)/2,(bt.frame.size.width-size.width)/2-image_sel.size.width,0,0); //设置图片的偏移量 :左偏移量设置 ,控件的宽度-图片的宽度)/2. 居中显示图片 [btn setImageEdgeInsets:UIEdgeInsetsMake(4, (WIDTH - imgNor.size.width)/2, 0, 0)];