2

アプリに背景画像付きの 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];

ゲームコン:

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)];

私は両方の答えが好きです。

結果: ここに画像の説明を入力

4

2 に答える 2

1

これを試して:

[self.loginButton setBackgroundImage:[[UIImage imageNamed:@"Button.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(10, 10, 10, 10)] forState:UIControlStateNormal];
于 2013-10-10T23:36:36.543 に答える