フォントが小さくて読みにくいので、下のボタンのフォントサイズに近づけたいと思います。
8 に答える
以下のように、showメソッド(showFromBarButtonItemなど)の後にフォントプロパティを変更できます。
CGRect oldFrame = [(UILabel*)[[sheet subviews] objectAtIndex:0] frame];
UILabel *newTitle = [[[UILabel alloc] initWithFrame:oldFrame] autorelease];
newTitle.font = [UIFont boldSystemFontOfSize:17];
newTitle.textAlignment = UITextAlignmentCenter;
newTitle.backgroundColor = [UIColor clearColor];
newTitle.textColor = [UIColor whiteColor];
newTitle.text = @"My Title";
[sheet addSubview:newTitle];
[sheet release];
UIActionSheet Class Referenceから:
UIActionSheet はサブクラス化するようには設計されていないため、その階層にビューを追加するべきではありません。UIActionSheet API で提供されるよりも多くのカスタマイズでシートを表示する必要がある場合は、独自のシートを作成して でモーダルに表示できます
presentViewController:animated:completion:
。
ニムロッドが言ったように、ネイティブメソッドではこれを行うことはできません。UIActionSheet サブビューを確認し、適切なものを見つけて、そのプロパティを変更できます。
しかし
- この実装は、将来の iOS アップデートでクラッシュする可能性があります
- Apple があなたのアプリを拒否する可能性があります
- UIActionSheet は iPhone GUI のネイティブ要素であり、ユーザーはそれに慣れています
それで
使用するフォント サイズを変更しないでください。この UIActionSheet のタイトルが重要な場合は、別の方法でユーザーに表示する必要があります。
@ user651909の答えは私にとってはうまくいきますが、さらにいくつかの詳細を追加するだけです:
をinitWithTitle:@" "
作成するときに(空でない文字列に注意してください)UIActionSheet
、ビューの上部にテキスト用のスペースを確保する必要がありました。次に、 を実行した後[popupQuery showInView:self.view];
、oldFrame が初期化されるように彼の提案を追加しました。最後に、次のように追加しました。
[newTitle sizeToFit];
newTitle.frame = CGRectMake(oldFrame.origin.x,
oldFrame.origin.y,
oldFrame.size.width,
newTitle.frame.size.height);
oldFrame
の高さが私の大きなフォント (サイズ 20) に対して小さすぎたため、これが必要でした。また、この微調整を行っても、テキストを大きくしすぎると (boldSystemFontOfSize:26 より大きくすると)、テキストが下のボタンに近づきすぎたり、入り込んだりします。ボタンが上部に固定されているように見えるため、シートのフレームのサイズを変更しても役に立ちません。
おそらくやってる
CGRect oldFrame = [(UILabel*)[[sheet subviews] objectAtIndex:0] frame];
内部 API を使用しないという Apple のポリシーに違反していませんよね?
UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"Share" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Facebook", @"Twitter",nil];
[sheet showInView:self.view];
if (![[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
CGRect labelFrame = [(UILabel*)[[sheet subviews] objectAtIndex:0] frame];
[[[sheet subviews] objectAtIndex:0] removeFromSuperview];
UILabel *newTitle = [[UILabel alloc] initWithFrame:labelFrame];
newTitle.font = [UIFont boldSystemFontOfSize:17];
newTitle.textAlignment = UITextAlignmentCenter;
newTitle.backgroundColor = [UIColor clearColor];
newTitle.textColor = [UIColor whiteColor];
newTitle.text = @"Share";
[sheet addSubview:newTitle];
}
コーンコンが示したように、ポインタを取得して操作できます。あなたがやろうとしていることを正しく理解していれば、次のとおりです。
[sheet showInView:[self.view window]];
UILabel *title = [[sheet subviews] objectAtIndex:0];
title.font = [UIFont boldSystemFontOfSize:20];
title.textAlignment = UITextAlignmentCenter;
お役に立てれば !
UIActionSheet *as = [[UIActionSheet alloc] initWithTitle:@"SpecifySearch"
delegate:self
cancelButtonTitle:@"Cancel"
destructiveButtonTitle:nil
otherButtonTitles:@"UncategorizedContacts" , nil];
//as.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
[as showFromTabBar:self.tabBarController.tabBar];
if( as.subviews.count > 0
&& [[as.subviews objectAtIndex:0] isKindOfClass:[UILabel class]] ){
UILabel* l = (UILabel*) [as.subviews objectAtIndex:0];
[l setFont:[UIFont boldSystemFontOfSize:20]];
}
[as release];
まあ、それを行う方法があります-私はLTActionSheetという名前のgithubでUIActionSheetサブクラスを作成しました
他の人が言ったように、それを使用すると、あらゆる種類の悲惨なことが起こる可能性があります (私は配送コードをまだ持っていません... :-) ) 受け入れられるアプリで使用する場合は、私たち全員に知らせてください!