2

UINavigationBarすべての文字を大文字にしたいタイトルがあるので、「word」は「WORD」になります。

このナビゲーションバー内のボタンについても同じことをしたいと思います。

text-transform:uppercase;単語の外観を変更できるCSS属性のようなものがあるのではないかと思っていましたが、その値を取得すると、それでも生の値が返されます。

前もって感謝します

4

3 に答える 3

1

これは実際にはあなたが思っているよりも簡単です。NSStringを使用uppercaseStringしてこれを実現できます。

[myLabel setText:[myString uppercaseString]];

または、ニーズにより適しています:

for (UIBarButtonItem *button in self.navigationItem.rightBarButtonItems) { //Your nag bar
    [button setTitle:[[button title] uppercaseString]];
}

編集:文字列が変更されない例。

NSString *myString = @"hello";
NSString *mySecondString = @"world!";

UIBarButtonItem *item1 = [[UIBarButtonItem alloc] initWithTitle:[myString uppercaseString] style:UIBarButtonItemStyleBordered target:self action:nil];
UIBarButtonItem *item2 = [[UIBarButtonItem alloc] initWithTitle:[mySecondString uppercaseString] style:UIBarButtonItemStyleBordered target:self action:nil];
[self.navigationItem setRightBarButtonItems:[NSArray arrayWithObjects:item1,item2, nil]];

NSLog(@"%@ | %@",myString,mySecondString);//this will output the same as when it was originally created.
于 2012-12-07T09:57:44.997 に答える
0

を使用する[myString uppercaseString]と、元の文字列ではなく大文字の文字列を返すという欠点があります(実際には欠点ではありません..)。1つのオプションは、すべて大文字のフォントでUILabelを設定することです(Copperplateは単なる例です。オールキャップスフォント、あなたはおそらくより良いものを見つけるでしょう):

int height = navigationController.navigationBar.frame.size.height;
int width = navigationController.navigationBar.frame.size.width;

UILabel *navLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, width, height)];
navLabel.backgroundColor = [UIColor clearColor];
navLabel.textColor = [UIColor whiteColor];
navLabel.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.5];
navLabel.font = [UIFont fontWithName:@"Copperplate" size:18];
navLabel.textAlignment = UITextAlignmentCenter;

self.navigationItem.titleView = navLabel;
于 2012-12-07T10:05:04.953 に答える
0

がある !

NSString *myLowercaseString = @"a lowercase string";
NSString *myUppercaseString = [myLowercaseString uppercaseString];

の場合NSLog (@"%@", myUppercaseString);、次の出力が得られます。

小文字の文字列

次に、ボタンまたはナビゲーションバーのテキストプロパティを文字列に設定できます。

于 2012-12-07T09:57:51.537 に答える