button 圖片居右文字居左
- 默認(rèn)button中的圖片是左文字是右 最終想要的是這樣
[self.phoneLoginBtn setTitleEdgeInsets:UIEdgeInsetsMake(0,-self.phoneLoginBtn.imageView.size.width, 0, self.phoneLoginBtn.imageView.size.width)];
[self.phoneLoginBtn setImageEdgeInsets:UIEdgeInsetsMake(0, self.phoneLoginBtn.titleLabel.bounds.size.width, 0, -self.phoneLoginBtn.titleLabel.bounds.size.width)];
05.png
- 原始圖片是這樣的:
01.png
· 當(dāng)如下設(shè)置時(shí):效果是這樣的
- 02 向左40 等價(jià)于向右-40
// 02 向左40
[self.myButton setImageEdgeInsets:UIEdgeInsetsMake(0, 40, 0, 0)];
// 向右-40
[self.myButton setImageEdgeInsets:UIEdgeInsetsMake(0, 0, 0, -40)];
//
[self.myButton setImageEdgeInsets:UIEdgeInsetsMake(0, 20, 0, -20)];
![Uploading 03_421791.png . . .]
- 03 向右40 等價(jià)于向左-40
// 03 向右40
[self.myButton setImageEdgeInsets:UIEdgeInsetsMake(0, 0, 0, 40)];
[self.myButton setImageEdgeInsets:UIEdgeInsetsMake(0, -40, 0, 0)];
[self.myButton setImageEdgeInsets:UIEdgeInsetsMake(0, -20, 0, 20)];
03.png
04.png
- 也就是最終我們希望圖片上下位置不變top = 0, bottom = 0;向右位移一個(gè)label的寬度
同時(shí)標(biāo)題上下位置不變top = 0, bottom = 0;向左位移一個(gè)圖片的寬度
即 imageEdgeInsets = UIEdgeInsetsMake(0,0 + labelWidth,0,0 - labelWidth); 圖片相對(duì)初始狀態(tài)左邊距加了labelWidth,右邊減labelWidth代芜,以及titleEdgeInsets = UIEdgeInsetsMake(0,0 - imageViewWidth,0, 0 + imageViewWidth);
2. button自定義 重寫(xiě)layoutSubviews方法
- (void)layoutSubviews
{
[super layoutSubviews];
// 調(diào)整圖片
self.imageView.x = 0;
self.imageView.y = 0;
self.imageView.width = self.width;
self.imageView.height = self.imageView.width;
// 調(diào)整文字
self.titleLabel.x = 0;
self.titleLabel.y = self.imageView.height;
self.titleLabel.width = self.width;
self.titleLabel.height = self.height - self.titleLabel.y;
}
stringByAppendingPathComponent --后面默認(rèn)拼接路徑 /
NSString *str = @"hehe";
NSString *new = [str stringByAppendingPathComponent:@"nicai"];
// log ---> new----hehe/nicai
NSString *new2 = [str stringByAppendingString:@"nicai"];
// log ---> new----hehenicai
IOS MJExtension 關(guān)鍵字替換
[XMGVideosetupReplacedKeyFromPropertyName:^NSDictionary*{
return@{@"ID":@"id"};
}];