首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SizeToFit导航栏项目(UITextField)

SizeToFit导航栏项目(UITextField)
EN

Stack Overflow用户
提问于 2012-06-17 02:19:23
回答 2查看 1.2K关注 0票数 0

如何调整UITextField大小以适合整个UINavigationBar?到目前为止,我有这样的想法:

代码语言:javascript
复制
    locationField = [[UITextField alloc] initWithFrame:CGRectMake(37,7,246,31)];
    locationField.delegate = self;
    locationField.autoresizingMask = UIViewAutoresizingFlexibleWidth;
    locationField.textColor = [UIColor colorWithRed:102.0/255 green:102.0/255 blue:102.0/255 alpha:1.0];
    locationField.textAlignment = UITextAlignmentLeft;
    locationField.borderStyle = UITextBorderStyleRoundedRect;
    locationField.font = [UIFont fontWithName:@"Helvetica" size:15];
    locationField.autocorrectionType = UITextAutocorrectionTypeNo;
    locationField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;

我基本上想使用locationField = [[UITextField alloc] initWithFrame:CGRectMake(37,7,246,31)];来适应UINavigationBar,可能是使用sizeToFit,只是不是100%确定如何实现它。

谢谢。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-06-17 05:31:54

您可以尝试使用

代码语言:javascript
复制
[self.navigationItem setTitleView:locationField];

请看下面的代码:

代码语言:javascript
复制
    UITextField *locationField = [[UITextField alloc] initWithFrame:CGRectMake(37,7,246,31)];
    locationField.delegate = self;
    locationField.autoresizingMask = UIViewAutoresizingFlexibleWidth;
    locationField.textColor = [UIColor colorWithRed:102.0/255 green:102.0/255 blue:102.0/255 alpha:1.0];
    locationField.textAlignment = UITextAlignmentLeft;
    locationField.borderStyle = UITextBorderStyleRoundedRect;
    locationField.font = [UIFont fontWithName:@"Helvetica" size:15];
    locationField.autocorrectionType = UITextAutocorrectionTypeNo;
    locationField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    [self.navigationItem setTitleView:locationField];
    [locationField release];
票数 2
EN

Stack Overflow用户

发布于 2012-06-18 01:27:16

不要紧,通过将CGRect从以下位置切换得到修复:

代码语言:javascript
复制
UITextField *locationField = [[UITextField alloc] initWithFrame:CGRectMake(37,7,246,31)];

代码语言:javascript
复制
UITextField *locationField = [[UITextField alloc] initWithFrame:CGRectMake(37,7,300,31)];
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11065942

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档