1:在XCode6之后使用pch:
修改工程配置文件,將創建的PCH file的路徑添加到TARGERS->Build Settings->Apple LLVM ->Prefix Header 的選項中去,注意Debug和Release兩欄都要添加:
注意使用$(SRCROOT)關鍵字代替項目文件之前的文件索引。這樣文件位置變化就不會造成錯誤啦。
$(SRCROOT)/JYPickViewDemo/JYPickViewDemo-Prefix.pch
2:錯誤:ld: 15 duplicate symbols for architecture x86_64
搜索工程目錄文件并沒有發現重復。然而:
刪去上圖中的重復文件即可。
注意:imageView的userInteractionEnabled會影響到Button的點擊事件
[self.container addSubview:imageView];
[imageView addSubview:Button];
如果想輸出2016-07-07 這樣的格式,在%后面加上02
NSString *birthDay = [NSString stringWithFormat:@"%ld-%02ld-%02ld", self.datePicker.date.year, self.datePicker.date.month, (long)self.self.datePicker.date.day];
對于collectionView和tableView,注意一下屬性
self.edgesForExtendedLayout = UIRectEdgeNone;
self.automaticallyAdjustsScrollViewInsets = NO;
編譯合并靜態庫
lipo -create /Users/jieyuanzhuang/Library/Developer/Xcode/DerivedData/uiforyysdk-ftqeflovhezxvpbkmqwihldszywq/Build/Products/Debug-iphonesimulator/libuiforyysdk.a /Users/jieyuanzhuang/Library/Developer/Xcode/DerivedData/uiforyysdk-ftqeflovhezxvpbkmqwihldszywq/Build/Products/Release-iphoneos/libuiforyysdk.a -output /Users/jieyuanzhuang/Desktop/libuiforyysdk.a
UITextField的異常情況,如下圖
@implementation UITextField(UITextFieldForbbidenPaste)
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender {
if (action == @selector(paste:)) {
return NO;
}
return [super canPerformAction:action withSender:sender];
}
是因為上面的代碼造成的。
自定義present的tip
How to present view controller from right to left in iOS using Swift
Objc
CATransition *transition = [[CATransition alloc] init];
transition.duration = 0.5;
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromRight;
[self.view.window.layer addAnimation:transition forKey:kCATransition];
[self presentViewController:dashboardWorkout animated:false completion:nil];
Swift 3
let transition = CATransition()
transition.duration = 0.5
transition.type = kCATransitionPush
transition.subtype = kCATransitionFromRight
view.window!.layer.add(transition, forKey: kCATransition)
present(dashboardWorkout, animated: false, completion: nil)
藍色文件夾和黃色文件夾
藍色文件夾(folder)一般作為資源文件夾使用,與黃色文件夾的主要區別是不參與編譯,所以說如果你在這些文件夾下編寫的邏輯代碼是不參與編譯的,其他文件也不能直接引用它們,若引用其中文件需要全路徑。
添加方式:
選擇Create folder references
黃色文件夾(group)是邏輯文件夾,主要是為了邏輯上的分組,如果手動創建(通過New Group選項)group并不會真正創建一個文件夾文件,該文件夾下的文件則會散亂的存放在工程根目錄下。當然我們通常會讓Xcode中的文件樹與實際工程文件中的文件樹保持一致。
選擇Create groups
最后來說明一下Copy items if needed這個選項
勾選后,會自動復制一份相同的文件到你的工程中,引用的是復制后在工程目錄中的位置。若不勾選,文件的引用位置則是文件的原位置(不建議這樣做,如果該文件在工程外被刪除,工程則無法引用,所以還是復制一份到工程中,這樣更利于工程文件的管理)。
關于自定義searchBar
#import "UISearchBar+Add.h"
@interface GRCustomSearchBar ()<UISearchBarDelegate>
@property (strong, nonatomic) UILabel *searchBarPlaceHolderLabel;
@end
@implementation GRCustomSearchBar
- (id)initWithFrame:(CGRect)frame{
self = [super initWithFrame:frame];
if (self) {
[self conficUI];
}
return self;
}
- (id)initWithCoder:(NSCoder *)aDecoder{
self = [super initWithCoder:aDecoder];
if (self) {
[self conficUI];
}
return self;
}
- (void)dealloc{
self.delegate = nil;
}
- (void)conficUI{
self.delegate = self;
self.backgroundImage = [UIImage new];
self.barTintColor = [UIColor whiteColor];
UITextField *searchField = [self valueForKey:@"searchField"];
if (searchField) {
searchField.backgroundColor = [UIColor whiteColor];
searchField.layer.cornerRadius = 5.0f;
searchField.layer.borderColor = [UIColor whiteColor].CGColor;
searchField.layer.borderWidth = 1;
searchField.layer.masksToBounds = YES;
//修正光標顏色
[searchField setTintColor:RGB(51, 51, 51)];
}
//設置輸入框文字顏色和字體
[self fm_setTextColor:RGB(51, 51, 51)];
[self fm_setTextFont:[UIFont systemFontOfSize:16]];
//自定義 PlaceHolder
UILabel *label = [UILabel new];
label.frame = CGRectMake(42, 8, 250, 28);
label.text = @"型號,材料,風格類型";
label.font = [UIFont systemFontOfSize:16];
label.textColor = RGB(229, 229, 229);
self.searchBarPlaceHolderLabel = label;
[self addSubview:label];
//自定義搜索Icon
//先設置一個leftView使得searchField光標右移
UIButton *tmpButton = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 18, self.width)];
searchField.leftView = tmpButton;
[searchField setLeftViewMode:UITextFieldViewModeAlways];
UIButton *searchButton = [UIButton buttonWithType:UIButtonTypeCustom];
[searchButton setImage:[UIImage imageNamed:@"搜索"] forState:UIControlStateNormal];
[searchField addSubview:searchButton];
//Autolayout
searchButton.translatesAutoresizingMaskIntoConstraints = NO;
NSDictionary *views = NSDictionaryOfVariableBindings(searchButton);
//設置水平方向約束
[searchField addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"|-[searchButton(21)]" options:NSLayoutFormatAlignAllRight | NSLayoutFormatAlignAllLeft metrics:nil views:views]];
//設置高度約束
[searchField addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[searchButton(21)]" options:NSLayoutFormatAlignAllTop | NSLayoutFormatAlignAllBottom metrics:nil views:views]];
//設置垂直方向居中約束
[searchField addConstraint:[NSLayoutConstraint constraintWithItem:searchButton attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:searchField attribute:NSLayoutAttributeCenterY multiplier:1 constant:0]];
}
#pragma mark - UISearchBarDelegate
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {
self.searchBarPlaceHolderLabel.hidden = searchText.length > 0;
}
- (BOOL)searchBar:(UISearchBar *)searchBar shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
self.searchBarPlaceHolderLabel.hidden = searchBar.text.length > 0;
return YES;
}
@end
其中UISearchBar+Add.h
#import "UISearchBar+Add.h"
@implementation UISearchBar (Add)
- (void)fm_setTextFont:(UIFont *)font {
if (IS_IOS9) {
[UITextField appearanceWhenContainedInInstancesOfClasses:@[[UISearchBar class]]].font = font;
}else {
[[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setFont:font];
}
}
- (void)fm_setTextColor:(UIColor *)textColor {
if (IS_IOS9) {
[UITextField appearanceWhenContainedInInstancesOfClasses:@[[UISearchBar class]]].textColor = textColor;
}else {
[[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setTextColor:textColor];
}
}
- (void)fm_setCancelButtonTitle:(NSString *)title {
if (IS_IOS9) {
[[UIBarButtonItem appearanceWhenContainedInInstancesOfClasses:@[[UISearchBar class]]] setTitle:title];
}else {
[[UIBarButtonItem appearanceWhenContainedIn:[UISearchBar class], nil] setTitle:title];
}
}
- (void)fm_setCancelButtonFont:(UIFont *)font {
NSDictionary *textAttr = @{NSFontAttributeName : font};
if (IS_IOS9) {
[[UIBarButtonItem appearanceWhenContainedInInstancesOfClasses:@[[UISearchBar class]]] setTitleTextAttributes:textAttr forState:UIControlStateNormal];
}else {
[[UIBarButtonItem appearanceWhenContainedIn:[UISearchBar class], nil] setTitleTextAttributes:textAttr forState:UIControlStateNormal];
}
}
@end
然而遇到一個很無解的問題:
當輸入超過一行的時候,光標向下偏移。
UIImageView *arrowDown = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"p-dropdown"]];
arrowDown.frame = CGRectMake(0, 0, 26, 22);
_province.rightViewMode = UITextFieldViewModeAlways;
_province.rightView = arrowDown;
_address.rightViewMode = UITextFieldViewModeAlways;
_address.rightView = arrowDown;
上面的這種寫法會導致app 卡死,因為兩個不同的UITextField不能使用相同的leftView或rightView.