簡體   English   中英

UIButton背景邊​​框iOS的問題

[英]issue with UIButton background borders iOS

我的應用程序中有一個帶有背景圖片的UIButton,這個

在此處輸入圖片說明

我想延長它的時間,並將以下內容添加到我的代碼中:

UIImage *backgroundButton = [UIImage imageNamed:@"Button.png"];
        [backgroundButton resizableImageWithCapInsets:UIEdgeInsetsMake(10, 10, 10, 10)];
        [backgroundButton imageWithAlignmentRectInsets:UIEdgeInsetsMake(10, 10, 10, 10)];

        [self.loginButton setBackgroundImage:[backgroundButton imageWithAlignmentRectInsets:UIEdgeInsetsMake(10, 10, 10, 10)] forState:UIControlStateNormal];

我試圖為避免這種情況留一些余量

在此處輸入圖片說明

如何獲得第一個按鈕的相同結果,但大小如此? 預先感謝您的支持


**編輯*****

我將把兩種方法都提供給我們的開發人員

耶穌:

[self.loginButton setBackgroundImage:[[UIImage imageNamed:@"Button.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(10, 8, 10, 8)] forState:UIControlStateNormal];

gameCon:

UIImage *modifiedBackgroundButton = [backgroundButton resizableImageWithCapInsets:UIEdgeInsetsMake(10, 10, 10, 10)];
        [self.loginButton setBackgroundImage:[modifiedBackgroundButton imageWithAlignmentRectInsets:UIEdgeInsetsMake(10, 10, 10, 10)] forState:UIControlStateNormal];

        [backgroundButton resizableImageWithCapInsets:UIEdgeInsetsMake(10, 10, 10, 10)];
        [backgroundButton imageWithAlignmentRectInsets:UIEdgeInsetsMake(10, 10, 10, 10)];

我喜歡這兩個答案,耶穌非常精確,gameCon使用了我自己的代碼來幫助我,謝謝大家的幫助!!!

結果: 在此處輸入圖片說明

如我們所見,您拉伸的背景圖片實際上沒有設置上限。 您必須存儲和處理此方法的結果(此代碼實際上不執行任何操作):

[backgroundButton resizableImageWithCapInsets:UIEdgeInsetsMake(10, 10, 10, 10)];
[backgroundButton imageWithAlignmentRectInsets:UIEdgeInsetsMake(10, 10, 10, 10)];

因此正確的方法是:

UIImage *modifiedBackgroundButton = [backgroundButton resizableImageWithCapInsets:UIEdgeInsetsMake(10, 10, 10, 10)];
[self.loginButton setBackgroundImage:[modifiedBackgroundButton imageWithAlignmentRectInsets:UIEdgeInsetsMake(10, 10, 10, 10)] forState:UIControlStateNormal];

嘗試這個:

[self.loginButton setBackgroundImage:[[UIImage imageNamed:@"Button.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(10, 10, 10, 10)] forState:UIControlStateNormal];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM