UISearchBar搜索图标在iOS7中未对齐 [英] UISearchBar search icon isnot left aligned in iOS7

查看:81
本文介绍了UISearchBar搜索图标在iOS7中未对齐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在iOS7中,搜索图标和占位符文本总是出现在中间。我尝试将搜索栏中文本字段的文本对齐方式更改为左边但是它不起作用。
有没有办法让搜索栏搜索图标在iOS7中显示左对齐

In iOS7 the search icon and place holder text are always appearing in middle.I tried changing the text alignment of the text field in search bar to left but it didn't work. Is there any way to make the searchbar search icon appear left aligned in iOS7

我尝试了以下几行,但它没有用:

I tried the following lines but it did not work:

UITextField *txfSearchField = [_searchBar valueForKey:@"_searchField"];
txfSearchField.textAlignment = NSTextAlignmentLeft;

[_searchArticle setImage:image forSearchBarIcon:UISearchBarIconSearch    state:UIControlStateNormal];
UIimageView *im = [UIImageView alloc]init];
im.image = image;
txfSearchField.leftView =im;


推荐答案

无法更改搜索栏的对齐方式占位符文本,我尝试了很多SO答案,但没有人工作。最后,我以此解决方法结束

There is no way to change the alignment of search bar's placeholder text, I tried so many "SO" answer but no one was working. Finally I ended with this workaround

在占位符文本右侧留出一些空格

Give some white space in right of placeholder text

    if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) {
        // Load resources for iOS 6.1 or earlier
        self.searchBar.placeholder = @"hello";
   } else {
       // Load resources for iOS 7 or later
       self.searchBar.placeholder = @"hello             ";
  }

享受!!

这篇关于UISearchBar搜索图标在iOS7中未对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆