9

字体非常小,有些人难以阅读,所以我想让它更接近下方按钮上使用的字体大小。

4

8 回答 8

16

您可以在显示方法(如 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];
于 2011-06-06T13:40:34.547 回答
2

就像 Nimrod 说的那样,您不能使用本机方法来做到这一点。您可以检查 UIActionSheet 子视图,找到好的子视图并更改其属性。

  • 此实现可能会在未来的 iOS 更新中崩溃
  • Apple 可能会拒绝您的应用
  • UIActionSheet 是 iPhone GUI 的原生元素,用户对它很熟悉

所以

你真的不应该改变使用的字体大小。如果这个 UIActionSheet 标题很重要,你应该找到另一种方式向用户展示它......

于 2010-10-13T09:02:14.203 回答
2

@user651909 的回答对我很有用,尽管只是为了添加更多细节:

创建时我必须initWithTitle:@" "(注意非空字符串),UIActionSheet以便视图在顶部有一些空间供任何文本开始。然后,在做了 a 之后[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]; 

不违反 Apple 不使用任何内部 API 的政策,对吧?

于 2011-11-18T02:00:08.933 回答
2

UIActionSheet 类参考

UIActionSheet 不是为子类而设计的,也不应该将视图添加到它的层次结构中。如果您需要呈现比 UIActionSheet API 提供的自定义更多的表单,您可以创建自己的表单并使用presentViewController:animated:completion:.

于 2014-02-27T01:42:31.127 回答
1
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];
 }
于 2013-09-10T07:23:32.870 回答
0

Well, there is a way to do it - I created a UIActionSheet subclass on github named LTActionSheet

As others mentioned, all kinds of dire things may happen if you use it (I have not in shipping code ... yet :-) ) If you use it in an app that gets accepted, please let us all know!

于 2011-08-04T15:31:03.090 回答
0

正如conecon 所展示的,您可以获得指向它的指针并对其进行操作。如果我理解正确你想要做的是:

[sheet showInView:[self.view window]];
UILabel *title = [[sheet subviews] objectAtIndex:0];
title.font = [UIFont boldSystemFontOfSize:20];
title.textAlignment = UITextAlignmentCenter;

希望这可以帮助 !

于 2012-08-23T15:57:24.130 回答
0
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];
于 2012-06-10T08:44:42.630 回答