3

我有一个 iPad 应用程序(XCode5、ARC、Storyboards、iOS 7)。这是问题(UITextField 中间的占位符和光标):

在此处输入图像描述

这是创建它的代码:

- (IBAction)bSendFeedback:(UIButton *)sender {

//  make the popover
UIViewController* popoverContent = [[UIViewController alloc] init];
UIView* popoverView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 450, 500)];
popoverView.backgroundColor = [UIColor colorWithWhite:(CGFloat)1.0 alpha:(CGFloat)1.0];  //  frame color?
popoverContent.view = popoverView;

//resize the popover view shown in the current view to the view's size
popoverContent.contentSizeForViewInPopover = CGSizeMake(450, 500);

//  add the UITextfield to the popover
UITextField *tf = [[UITextField alloc]initWithFrame:CGRectMake(0, 0, 450, 500)];
[tf becomeFirstResponder];
tf.delegate = self;
tf.tag = kSendFeedback;
tf.placeholder = @" Enter your comments here";
tf.backgroundColor = UIColorFromRGB(0xFFFFE0);
tf.returnKeyType = UIReturnKeyDone;  //  make return key read "Done"
[popoverView addSubview:tf];

//  if previous popoverController is still visible... dismiss it
if ([popoverController isPopoverVisible]) {
    [popoverController dismissPopoverAnimated:YES];
}

//create a popover controller
popoverController = [[UIPopoverController alloc] initWithContentViewController:popoverContent];
[popoverController presentPopoverFromRect:((UIButton *)oSendFeedback).frame inView:self.view
                 permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

}

图片来自iOS7下运行;它在 iOS 6 下运行时工作正常。 正如你所见,它有点工作,但光标/占位符应该在 UITextField 的顶部......有什么想法为什么在 ios& 下运行时它不存在?

4

1 回答 1

8

似乎 Apple 已将 UITextField 的默认垂直对齐方式更改为 iOS 7 中的居中 ( UIControlContentVerticalAlignmentCenter) 与 iOS 6 和以前版本中的顶部 ( UIControlContentVerticalAlignmentTop)。

要在所有版本中修复它,请添加此行 -

tf.contentVerticalAlignment = UIControlContentVerticalAlignmentTop;

这会将光标和占位符文本放在顶部。接得好 !!

于 2013-10-22T19:25:22.373 回答