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

查看:21
本文介绍了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天全站免登陆