日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

UIButton中的三个UIEdgeInsets属性

發(fā)布時間:2024/4/14 编程问答 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 UIButton中的三个UIEdgeInsets属性 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

接著昨天的 UIButton中的三個UIEdgeInsets屬性 ,今天我們具體談?wù)刄IButton的contentEdgeInsets、titleEdgeInsets、imageEdgeInsets屬性。?

創(chuàng)建UIButton

UIButton *button = [[UIButton alloc] init];button.frame = CGRectMake(50, 200, 200, 50);[button setTitle:@"我是UIButton" forState:UIControlStateNormal];[button setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];[button setBackgroundColor:[UIColor orangeColor]];button.titleLabel.textAlignment = NSTextAlignmentLeft;button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;[self.view addSubview:button];

?

創(chuàng)建一個button,讓button的title居左,以便觀察:

UIButton的contentEdgeInsets屬性

@property(nonatomic)UIEdgeInsets contentEdgeInsets UI_APPEARANCE_SELECTOR; // default is UIEdgeInsetsZero

?

contentEdgeInsets里有一個content應(yīng)該指的就是UIButton的title。

參數(shù)含義

上一篇文章我們講了UIEdgeInsets是個結(jié)構(gòu)體類型。里面有四個參數(shù),分別是:top, left, bottom, right。這四個參數(shù)表示距離上邊界、左邊界、下邊界、右邊界的距離。

這四個參數(shù)的值可以為正值,也可以為負值。拿left舉例:

left = 10; //代表以當(dāng)前位置為基準(zhǔn),向右移動10個像素left = -10; //代表以當(dāng)前位置為基準(zhǔn),向左移動10個像素

向右移動20個像素

button.contentEdgeInsets = UIEdgeInsetsMake(0, 20, 0, 0);

?

向右移動20個像素,left = 20,就可以了。

向左移動20個像素

button.contentEdgeInsets = UIEdgeInsetsMake(0, -20, 0, 0);

UIButton的titleEdgeInsets屬性

titleEdgeInsets和contentEdgeInsets的作用差不多。我們及設(shè)置contentEdgeInsets,又設(shè)置titleEdgeInsets,會怎樣呢?

button.titleEdgeInsets = UIEdgeInsetsMake(0, 20, 0, 0);button.contentEdgeInsets = UIEdgeInsetsMake(0, 20 , 0, 0);

?

看一下效果:

UIButton的titleEdgeInsets屬性

創(chuàng)建一個帶照片的button

UIButton *button = [[UIButton alloc] init]; button.frame = CGRectMake(50, 200, 200, 200); [button setTitleColor:[UIColor blueColor] forState:UIControlStateNormal]; [button setBackgroundColor:[UIColor orangeColor]]; [button setImage:[UIImage imageNamed:@"test"] forState:UIControlStateNormal]; [self.view addSubview:button];

?

運行一下:

向右移動50個像素

button.imageEdgeInsets = UIEdgeInsetsMake(0, 50, 0, 0);

?

看看效果:

向左移動50個像素

button.imageEdgeInsets = UIEdgeInsetsMake(0, -50, 0, 0);

?

看看效果:

總結(jié)

以上是生活随笔為你收集整理的UIButton中的三个UIEdgeInsets属性的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。