-2

私はアプリを開発していて、グローバル形式を適用するために、次の行を appDelegate.m ファイルに追加しました。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{

    [self customizeAppearance];

    return YES;
}

-(void)customizeAppearance{

    int iOSVersion = [[[UIDevice currentDevice]systemVersion] intValue];

    if (iOSVersion >= 7) {

        //Customizing UIButton
        [[UIButton appearance]setBackgroundColor:(UIColorFromRGB(toolbarTintColor))];
        [[UIButton appearance]setTitleColor:(UIColorFromRGB(toolbarTextColor)) forState:UIControlStateNormal];

      }

    if (iOSVersion < 7) {

        //Customizing UIButton
        [[UIButton appearance]setBackgroundImage:[UIImage imageNamed:@"Button.png"] forState:UIControlStateNormal];
    }
}

UIbuttonスタイルを変更するiOSバージョンに応じてこれら2つのスタイルを実行しましたが、UIBarButtonItemsではなくUIButtonsにのみ適用したいのですが、それは可能ですか??

これをさらに一歩進めて、このフォーマットをUIView要素内のUIButtons(UITableViewCellsなどではなく)にグローバルに適用したいのですが、それはできますか???

サポートを事前に感謝します

4

2 に答える 2

1

以下のプロキシを使用できます。

[[UIButton appearanceWhenContainedIn:[MyView class], nil] setBackgroundColor:[UIColor greenColor]];

詳細については、これを確認してください。

ちなみに、 の外観を設定しUIButtonても の外観は変わりませんUIBarButtonItems

于 2013-10-01T17:42:43.430 に答える
1

これを行う方法は、説明した方法で機能する必要があります。名前が示すように、UIBarButtonItem は UIButton から継承しません。つまり、UIButton で UIAppearance プロトコルを使用すると、行った変更は UIBarButtonItem のインスタンスには影響しません。

NSObject >> UIBarItem >>UIBarButtonItem

NSObject >> UIResponder >>UIView >> UIControl >> UIButton

2 番目の質問に答えるには、ボタンの特定のインスタンスにのみカスタマイズを適用する場合は、カスタマイズする UIButton のサブクラスを作成する方がよいでしょう。これにより、スーパービューのクラスに応じてサブクラスの外観を変更するロジックをサブクラスに追加できます。これは、次のようなものを使用して実行できます。

[self.superview isKindOfClass:[UITableViewCell class]];

または、まだ UIAppearance を使用したい場合は、例として @null の回答を参照してください。

于 2013-10-01T17:43:39.660 に答える