iOS学習のbutton書き換え方法buttonの画像文字の位置を変える
buttonの書き換え方法buttonの画像文字の位置を変更する.書き換え方法は、画像の位置をtitleRect.に変更する.メソッドの後に実行
2.title文字の位置を変更し、titleの矩形を構築すればよい
- (CGRect)imageRectForContentRect:(CGRect)contentRect
{
CGFloat imageX=self.frame.size.width/2+boundingRect.size.width/2;
UIScreen *s=[UIScreen mainScreen];
CGRect rect=s.bounds;
CGFloat imageY=contentRect.origin.y+14;
CGFloat width=24;
CGFloat height=24;
return CGRectMake(imageX, imageY, width, height);
}
2.title文字の位置を変更し、titleの矩形を構築すればよい
- (CGRect)titleRectForContentRect:(CGRect)contentRect
{
CGFloat imageX=(self.frame.size.width-boundingRect.size.width)/2;
CGFloat imageY=contentRect.origin.y+10;
CGFloat width=220;
CGFloat height=25;
return CGRectMake(imageX, imageY, width, height);
}