1

わかりました、皆さん、

私は何か間違ったことをしていることを知っていますが、それを理解することはできません。これは、通常のボタン状態のサイズ変更可能な画像を配置するコードです。

self.loginButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.loginButton.frame = CGRectMake(0.0, 44.0, 314, 44);
    UIImage *image = [[UIImage imageNamed:@"loginbutton_image"] resizableImageWithCapInsets:UIEdgeInsetsMake(0.0,10.0,0.0,10.0)];
    [self.loginButton setImage:image forState:UIControlStateNormal];
    [self addSubview:self.loginButton];

画像はこちら

ここに画像の説明を入力

画像アセットが間違っているか、コードが間違っています。

画像の幅は 21 px です。左右の 10 & 10 のキャップ インセットは、サイズ変更する 1Px を残します。

私が間違っていることを誰かが見つけますか。

アルンに立ち寄ってくれてありがとう

4

2 に答える 2

10

このようにする必要があります:

self.loginButton = [UIButton buttonWithType:UIButtonTypeCustom];
self.loginButton.frame = CGRectMake(0.0, 44.0, 314, 44);
UIImage *image = [[UIImage imageNamed:@"loginbutton_image"] resizableImageWithCapInsets:UIEdgeInsetsMake(0.0,10.0,0.0,10.0)];
[self.loginButton setBackgroundImage:image forState:UIControlStateNormal];
[self.view addSubview:self.loginButton];

このようにして、ボタンの背景画像プロパティを設定しています。背景画像は既にボタン ビューにアタッチされているため、サブビューを追加する必要はありません。

于 2012-07-11T01:13:48.200 に答える
0

試す

self.loginButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.loginButton.frame = CGRectMake(0.0, 44.0, 314, 44);
    UIImage *image = [[UIImage imageNamed:@"loginbutton_image"] stretchableImageWithLeftCapWidth:10 topCapHeight:10]; //assuming the height is 44
    [self.loginButton setImage:image forState:UIControlStateNormal];
    [self addSubview:self.loginButton];
于 2012-07-11T01:23:27.990 に答える