0

デフォルトのiOSUIButton(ストーリーボード内)があります。

変更したい(border-radiusの削除、実線の境界線の追加、背景の変更など)。コードはどこに書くべきですか?どの方法を使用すればよいですか?どのクラスをインポートする必要がありますか?

4

3 に答える 3

2

customInterface Builderでボタンの種類を選択することで、すべてではないにしても、ほとんどのことを実行できます。それでもすべてが達成されない場合は、コードを使用してこれをすべて設定できます。

ファイルにあることを確認#import <QuartzCore/QuartzCore.h>してください。.m

プロパティを設定します(このSO回答のベース):

float borderWidth = ...;
UIColor *borderColor = ...; // create the color you want

[[myButton layer] setBorderWidth:borderWidth];
[[myButton layer] setBorderColor:borderColor.CGColor];

同様の方法で、必要なすべてのボタンプロパティを確認できます。((

于 2013-02-25T17:25:29.563 に答える
0

私の単純なコードでは、次のようなものがあります。

@property (nonatomic, strong) UIButton *rssButton;

次に、実装でこのボタンを定義します。

- (UIButton *)rssButton {
    if(_rssButton == nil) {
        _rssButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        _rssButton.frame = CGRectMake(60, 200, 200, 40);
        [_rssButton setTitle:@"Get newest RSS article" forState:UIControlStateNormal];
        _rssButton.titleLabel.textColor = [UIColor colorWithRed:0.294 green:0.553 blue:0.886 alpha:1];
        _rssButton.backgroundColor = [UIColor whiteColor];

        _rssButton.layer.borderColor = [UIColor blackColor].CGColor;
        _rssButton.layer.borderWidth = 0.5f;
        _rssButton.layer.cornerRadius = 10.0f;

        [_rssButton addTarget:self action:@selector(getDataFromRSS) forControlEvents:UIControlEventTouchUpInside];
    }
    return _rssButton;
}

次に、メインビューに追加します。

[self.view addSubview:self.rssButton];
于 2013-02-25T17:25:17.380 に答える
0

プロパティ定義を次のように変更する必要があります。

@property (nonatomic, strong) IBOutlet UIButton *rssButton;

そして、UIButtonオブジェクトをストーリーボードからこのプロパティに接続すると、コードを介してオブジェクトを好きなように変更できます(同じコントローラーでこれを実行していると仮定します)

ストーリーボードですでに定義されている場合は、そのボタンをビューに追加する最後の行を削除します

于 2013-02-25T17:29:11.103 に答える