にクロッピングし、ブックマークボタンをオーバーレイ検索バーを選択しなくなるまで:UISearchBarプレースホルダ位置合わせとiOS 7 UISearchbarプレースホルダ中央揃えでIOSの7
それが選択すると、期待どおりに見えます。
私はそれがこのようにすべての時間に見える必要があります。ありがとうございました。
にクロッピングし、ブックマークボタンをオーバーレイ検索バーを選択しなくなるまで:UISearchBarプレースホルダ位置合わせとiOS 7 UISearchbarプレースホルダ中央揃えでIOSの7
それが選択すると、期待どおりに見えます。
私はそれがこのようにすべての時間に見える必要があります。ありがとうございました。
-(void)viewDidAppear:(BOOL)animated{
[email protected]"woord hier invoeren";
}
-(void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar{
[email protected]"woord hier invoeren.......";
}
私はあなたの一般解を与えるためにここにいないんだけど、あなたが追加するプレースホルダを持っている場合は、それを行うには非常識な簡単な方法は、プレースホルダを自分で切り捨てているので、代わりに
searchBar.placeholder = @ "woord hier invoeren";
searchBar.placeholder = @ "woordののhierのINVO ..." それは聞かせて。
私はリンゴのプライベートメソッドを運んでいましたが、運が無かった: searchBarのサブビューは、 -UISearchBarBackgroundです。 -UISearchBarTextField。 UISearchBarBackgroundを残しておきます。 UISearchBarTextFieldインスタンスのサブビューは、 -_UISearchBarSearchFieldBackgroundViewです。 -UIImageView。 -UISearchBarTextFieldLabel。
私が行ったのは、UISearchBarTextFieldLabel cozのrect(私はこれらがプライベートメソッドであるため、単語の混乱に重点を置いています)を混乱させようとしています。searchBarボタンが正しく表示されていないあなたがsearchBar.showsBookmarkButton = NOを選択した場合は表示(ブックマーク)。 placeHolderテキストは期待どおりに切り捨てられます。 これはあなた次第です。いつかあなた自身を救ってください。 良い仕事を続けてください。
新しいソリューション:
//
// WPViewController.m
// test
//
// Created by VASANTH K on 02/01/14.
//
//
#import "WPViewController.h"
@interface WPViewController()
{
UILabel *lableCopy;
}
@end
@implementation WPViewController
- (void)viewDidLoad
{
[super viewDidLoad];
//[self fixSearchBar:searchBar];
// Do any additional setup after loading the view, typically from a nib.
self.searchBar.delegate=self;
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[self.searchBar resignFirstResponder];
//[self fixSearchBar:searchBar];
}
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self fixSearchBar:self.searchBar];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)searchBarTextDidBeginEditing:(UISearchBar *)search
{
[self fixSearchBar:self.searchBar];
}
-(void)searchBarTextDidEndEditing:(UISearchBar *)searchBar
{
[self fixSearchBar:self.searchBar];
}
-(void)fixSearchBar:(UISearchBar*)searchBar
{
UITextField *searchField = [searchBar valueForKey:@"_searchField"];
// [searchField setValue:[UIColor blueColor] forKeyPath:@"_placeholderLabel.textColor"];
UILabel *lable=[searchField valueForKey:@"_placeholderLabel"];
if(!lableCopy)
{
lableCopy=[[UILabel alloc]initWithFrame:lable.frame];
lableCopy.font=lable.font;
[lableCopy setText:lable.text];
[lableCopy setTextColor:lable.textColor];
UIButton *button;
for (UIView *view in [[[[searchBar.subviews objectAtIndex:0] subviews] objectAtIndex:1] subviews]) {
if([view isKindOfClass:[UIButton class]])
{
button=(UIButton*)view;
break;
}
}
if(button)
{
//lable.hidden=YES;
CGRect newFrame=lable.frame;
newFrame.size.width=button.frame.origin.x-lable.frame.origin.x;
lableCopy.frame=newFrame;
[lableCopy adjustsFontSizeToFitWidth];
//lableCopy.backgroundColor=[UIColor blackColor];
[searchField addSubview:lableCopy];
lableCopy.text=lable.text;
//lableCopy.textColor=[UIColor redColor];
}
}
for (UIView *view in [[searchBar.subviews objectAtIndex:0] subviews]) {
if([view isKindOfClass:[UITextField class]])
{
// NSLog(@"%@",view);
NSLog(@"TextFieldPresent==>%@",view);
if([view isFirstResponder])
{
lable.hidden=NO;
lableCopy.hidden=YES;
}
else
{
lable.hidden=YES;
lableCopy.hidden=NO;
}
break;
}
}
}
@end
このソリューションは、ちょうど新しいUILableビューを追加し、検索バーがアクティブになったとき、実際のプレースホルダを再表示searchBar.Againの本当の感じを与えるために、既存のプレースホルダを隠しています。
これは、IOS7でのUIの問題を修正するための一時的なハックかもしれません。
OLD解決 [searchFieldのsetValue:[のNSNumber numberWithBool:YES] forKeyPath:@ "_ placeholderLabel.adjustsFontSizeToFitWidth"]。
は、コンテンツを表示するために使用されるlableのサイズがテキストを表示するのに十分であるため、ios7では動作しません。問題はios7のラベル幅のバグです。ラベル幅のサイズを変更することができません。
これを修正するための少しのハックがあります。
UITextField *searchField = [searchBar valueForKey:@"_searchField"];
UILabel *lable=[searchBar valueForKey:@"_placeholderLabel"];
lable.font=[UIFont fontWithName:lable.font.fontName size:10.0];
あなた自身の検索バーの幅に基づいてフォントサイズを計算します。私はまた、特定のラベルの幅を変更しようとしましたが、うまく動作しません。
フォントの値を計算する方法がわかりません私の場合のプレースホルダーのテキストは可変です。たまには1つの単語しか表示されず、プレースホルダーのラベルを塗りつぶして自動的にドット(...)に切り捨てます。 – JAHelia
@JAHeliaは今度は最新の回答を確認します。 – CoolMonster
ありがとうクールなハックのために – JAHelia
コードを入力してください。また、Appleにバグレポートを提出してください。 –
あなたは任意のフォントサイズが必要です – codercat
あなたのuisearchbarフレームサイズは何ですか – codercat