0

プログラムでボタンのサイズを変更したいのですが、パラメーターを変更しても効果がありません。

btnCancel = [UIButton buttonWithType:102];
[btnCancel setFrame:CGRectMake(22.0f, 7.0f, 40.0f, 40.0f)];
[btnCancel setTitle:@"Anuluj" forState:UIControlStateNormal];
[btnCancel setTintColor:[UIColor redColor]];
[btnCancel addTarget:self action:@selector(cancelTyping) forControlEvents:UIControlEventTouchUpInside];

理由はありますか?パラメータに好きな量を与えることができますが、結果は同じです-幅はテキストの長さに制限されます。

4

4 に答える 4

1

私はあなたのコードを受け取り、iOS 6.0 でテストしました。これはあなたがする必要があることの最終バージョンです

QuartzCore ライブラリを追加し、これをヘッダー ファイルに追加します。

#import <QuartzCore/QuartzCore.h> 

これが写真付きのボタンコードです。幅と高さをいじると、それらは変化します

UIButton *btnCancel =[UIButton buttonWithType:UIButtonTypeCustom];
    [btnCancel setFrame:CGRectMake(22.0f, 7.0f, 80.0f, 80.0f)];
    [btnCancel setTitle:@"Anuluj" forState:UIControlStateNormal];
    btnCancel.backgroundColor = [UIColor redColor];
    btnCancel.layer.borderColor = [UIColor redColor].CGColor;
    btnCancel.layer.borderWidth = 0.5f;
    btnCancel.layer.cornerRadius = 10.0f;
    [btnCancel addTarget:self action:@selector(cancelTyping) forControlEvents:UIControlEventTouchUpInside];

ここに画像の説明を入力

于 2013-06-25T20:49:55.663 に答える
0

btnCancel = [UIButton buttonWithType:102];で変えてみてくださいbtnCancel = [UIButton buttonWithType:UIButtonTypeCustom];

于 2013-06-25T20:22:48.643 に答える
0

ほとんどの場合、自動レイアウトがオンになっています。インターフェイスビルダーに移動してオフにすると、コードが機能するはずです

于 2013-06-25T20:23:01.813 に答える