Obj-Cを使用してiPhoneプログラミングでカスタムイメージをUIButtonsに適用する方法を説明するチュートリアルをいくつか実行しています。Interface BuilderのRound Rect Buttonにカスタムコードイメージを適用する際の問題
私が好きな一つの方法は、このようにXIBのビューコントローラの皮膚の「のviewDidLoad」メソッドで、その後にInterface Builderを使用してXIB上のボタンをUIButton(ラウンドのRectボタン)を配置することです:
UIImage *ButtonImageNormal = [UIImage imageNamed:@"button_blue.png"];
UIImage *StretchableButtonImageNormal = [ButtonImageNormal stretchableImageWithLeftCapWidth:24 topCapHeight:24];
[self.Button setBackgroundImage:StretchableButtonImageNormal forState:UIControlStateNormal];
UIImage *ButtonImagePressed = [UIImage imageNamed:@"button_orange.png"];
UIImage *StretchableButtonImagePressed = [ButtonImagePressed stretchableImageWithLeftCapWidth:24 topCapHeight:24];
[self.Button setBackgroundImage:StretchableButtonImagePressed forState:UIControlStateHighlighted];
トラブルこの方法では、ボタンが 'Round Rect'バックグラウンドを失うことはなく、ボタンの横には「Round Rect」ボタンの白がカスタム画像を覗いて見えることがあります。
の場合は、しかし、私はこのコードを使用してゼロからカスタムボタンを作成します。
UIButton *CustomButton = [UIButton buttonWithType:UIButtonTypeCustom];
[CustomButton setFrame:CGRectMake(20, 100, 280, 45)];
[CustomButton.titleLabel setFont:[UIFont boldSystemFontOfSize:15]];
[CustomButton setTitle:@"Custom Button" forState:UIControlStateNormal];
[CustomButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[CustomButton setBackgroundImage:[UIImage imageNamed:@"button_blue.png"] forState:UIControlStateNormal];
[CustomButton setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
[CustomButton setBackgroundImage:[UIImage imageNamed:@"button_orange.png"] forState:UIControlStateHighlighted];
[self.view addSubview:CustomButton];
を通して覗き、そのような白い背景がありません。
私は実際にボタンを配置してスキニングする 'Round Rect'メソッドを使用したいと思います。なぜなら、Interface builderでの位置を確認したいからです。私は使用する必要があるメソッドがあるか、コード内の 'Round Rect'ボタンの白い背景を取り除くために私が修正する必要があるプロパティがありますか?
ここで問題点を示す画像です:
多分私が言っているはずErrr、IBボタンタイプが "カスタム" であることを確認してください? –