相关疑难解决方法(0)

将文本垂直对齐到UILabel中的顶部

我有UILabel两行文字的空间.有时,当文本太短时,此文本显示在标签的垂直中心.

如何将文本垂直对齐以始终位于顶部UILabel

表示具有垂直居中文本的UILabel的图像

xcode cocoa-touch text-alignment uikit ios

2141
推荐指数
39
解决办法
64万
查看次数

UITextView上边距

我正在使用textview并注意到默认情况下iOS 7会留下一个上边距.请参阅以下图像在此输入图像描述

我阅读了最常用解决方案的不同帖子:

[textViewTest setContentInset:UIEdgeInsetsMake(<#CGFloat top#>, <#CGFloat left#>, <#CGFloat bottom#>, <#CGFloat right#>)];
Run Code Online (Sandbox Code Playgroud)

但这些插入只是特定设备,textview,字体大小等的自定义解决方案.因此,没有适用于任何解决方案的特定插件......即使最糟糕的是,我还必须以编程方式定义不同的插件以考虑所有iOS设备和方向.

好消息是,我发现每当textview成为第一个响应者并且键盘显示在屏幕上时,即使键盘消失,这个上边距也会消失.顺便说一句,我正在调整UIKeyboardDidShowNotification和UIKeyboardWillHideNotification上的contentInset.

  • 键盘确实显示时看到图像:

在此输入图像描述

  • 键盘消失时看图像:

在此输入图像描述

有没有办法模拟键盘显示和隐藏?因此内容插入消失了,如上所述.

我已经尝试使textview成为第一响应者然后重新签名,但是对于这种方法,用户必须看到整个键盘显示隐藏动画.

提前致谢!

我的代码如下:

- (void)viewDidLoad {
    [super viewDidLoad];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleKeyboardDidShow:) name:UIKeyboardDidShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleKeyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
    if(self.topMarginIsAlreadyResized == NO) {
        [self.myTextView becomeFirstResponder]; // Keyboard will show to eliminate top margin when view appears
    }
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (void)handleKeyboardDidShow:(NSNotification *)notification {
    if(self.topMarginIsAlreadyResized == NO) {
        self.topMarginIsAlreadyResized …
Run Code Online (Sandbox Code Playgroud)

uitextview uikeyboard ios

7
推荐指数
1
解决办法
3723
查看次数