解決ImageView/Button變形
- 保證圖片在不同比例手機(jī)上不會變形的方法;
_ImageView.contentMode = UIViewContentModeScaleAspectFill;
_ImageView.clipsToBounds = YES;
[nutritionButton setImage:[UIImage imageNamed:@"HG_Main_YYZJ"] forState:UIControlStateNormal];
[nutritionButton.imageView setContentMode:UIViewContentModeScaleAspectFill ];
- 分享一個寫的不錯的文章關(guān)于uiview視圖的小技巧
http://www.cnblogs.com/pengyingh/articles/2379476.html
動態(tài)高度
CGRect rect = [@"需要展示的文字" boundingRectWithSize:CGSizeMake(SCREEN_W - (SCREEN_W/10*2.6), MAXFLOAT)
options:NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading
attributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:14]} context:nil];
注釋:
1.CGSizeMake(SCREEN_W - (SCREEN_W/10*2.6), MAXFLOAT)
這段文字需要的寬高
2.[UIFont boldSystemFontOfSize:14]
這段文字的大小
自動布局
當(dāng)我們設(shè)置navBar為透明時 整個屏幕坐標(biāo)會向上64 衩匣,當(dāng)顯示時就會出現(xiàn)屏幕下移 涨岁,有人會說取動布局
self.automaticallyAdjustsScrollViewInsets = NO;
當(dāng)這個方法不好使的時候get大家一個新技能
self.extendedLayoutIncludesOpaqueBars = YES;
這個屬性看單詞的意思,延伸視圖包含不包含不透明的Bar,是用來指定導(dǎo)航欄是透明的還是不透明,IOS7中默認(rèn)是YES,當(dāng)滾動頁面的時候我們隱約能在導(dǎo)航欄下面看到我們頁面的試圖,如果設(shè)置為NO就會從導(dǎo)航欄下面展示我們的視圖
獲取當(dāng)前時間
NSDate *now = [NSDate date];
NSLog(@”now date is: %@”, now);
NSCalendar *calendar = [NSCalendar currentCalendar];
NSUInteger unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
NSDateComponents *dateComponent = [calendar components:unitFlags fromDate:now];
int year = [ dateComponent year];
int month = [dateComponent month];
int day = [dateComponent day];
int hour = [dateComponent hour];
int minute = [dateComponent minute];
int second = [dateComponent second];
NSLog(@”year is: %d”, year);
NSLog(@”month is: %d”, month);
NSLog(@”day is: %d”, day);
NSLog(@”hour is: %d”, hour);
NSLog(@”minute is: %d”, minute);
NSLog(@”second is: %d”, second);
MJ崩潰現(xiàn)象
MJRefresh出現(xiàn)崩潰現(xiàn)象
解決辦法:類庫增加判斷
if (range.location != NSNotFound) {
language = [language substringToIndex:range.location];
}
get一個關(guān)于 UIslider控件方法大全
https://my.oschina.net/u/2340880/blog/401902
改變self.title字體顏色
// NSDictionary * dict=@{NSForegroundColorAttributeName :[UIColor whiteColor]};
// self.navigationController.navigationBar.titleTextAttributes = dict;
軟件下載
http://www.orsoon.com/Mac/144664.html?winzoom=0.875
狀態(tài)欄
改變狀態(tài)欄顏色
info 添加View controller-based status bar appearance字段
[[UIApplication sharedApplication ]setStatusBarStyle:UIStatusBarStyleDefault];//黑色
[[UIApplication sharedApplication ]setStatusBarStyle:UIStatusBarStyleLightContent];//白色
狀態(tài)欄詳解
http://www.cnblogs.com/ethan-qi/p/5527588.html
http://blog.csdn.net/iukey/article/details/7327164
單個頁面需要旋轉(zhuǎn)時
#pragma mark 旋轉(zhuǎn)屏幕
- (UIInterfaceOrientationMask)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskLandscape;
}
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationLandscapeRight;
}
- (BOOL)prefersStatusBarHidden
{
return NO; // 返回NO表示要顯示干签,返回YES將hiden
}
iOS開發(fā)——OC篇&常用問題解答(一)
http://www.cnblogs.com/iCocos/p/4539000.html
富文本
NSString * ZJYDescribeStr = @" 點擊上面的注冊按鈕,即表示您同意《逐步環(huán)球的服務(wù)和隱私條款》";
NSRange rang = {22,14};
NSMutableAttributedString * att = [[NSMutableAttributedString alloc]initWithString:ZJYDescribeStr];
NSDictionary * dic = @{NSForegroundColorAttributeName:[[UIColor purpleColor]colorWithAlphaComponent:0.3]};
[att setAttributes:dic range:rang];
label.attributedText = att;
小技巧
在xcode中拆撼,大家可能會想要像瀏覽器一樣打開多個標(biāo)簽來查看多個文件的內(nèi)容容劳,因為之前遇到打開多個標(biāo)簽的情況,所以知道肯定有闸度〗叻罚可是找了半天也沒有找到打開多個標(biāo)簽在哪里
現(xiàn)在奉上快捷鍵:command + T
RGB
將一個 NSString = @“#FF0000”轉(zhuǎn)換成 RGB的方法
NSString *color = @“#FF0000”;
// 轉(zhuǎn)換成標(biāo)準(zhǔn)16進(jìn)制數(shù)
[color replaceCharactersInRange:[color rangeOfString:@"#" ] withString:@"0x"];
// 十六進(jìn)制字符串轉(zhuǎn)成整形。
long colorLong = strtoul([color cStringUsingEncoding:NSUTF8StringEncoding], 0, 16);
// 通過位與方法獲取三色值
int R = (colorLong & 0xFF0000 )>>16;
int G = (colorLong & 0x00FF00 )>>8;
int B = colorLong & 0x0000FF;
//string轉(zhuǎn)color
UIColor *wordColor = [UIColor colorWithRed:R/255.0 green:G/255.0 blue:B/255.0 alpha:1.0];
自定義手勢收起鍵盤
- (void)viewDidLoad
{
[super viewDidLoad];
UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(keyboardHide:)];
//設(shè)置成NO表示當(dāng)前控件響應(yīng)后會傳播到其他控件上莺禁,默認(rèn)為YES留量。
tapGestureRecognizer.cancelsTouchesInView = NO;
//將觸摸事件添加到當(dāng)前view
[self.view addGestureRecognizer:tapGestureRecognizer];
}
-(void)keyboardHide:(UITapGestureRecognizer*)tap{
[textFiled resignFirstResponder];
}
設(shè)備號ID的獲取
//設(shè)備id獲取
#define DEVICE [[UIDevice currentDevice].identifierForVendor UUIDString]
更改適配
Build Active Architecture Only
Debug Yes
Release No
滑動tableView時 收起鍵盤
_tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;