咱们在写程序的时候,屏幕的宽高咱们不能写固定,例如写成320,480之类的,由于咱们要适配不一样的手机。经常使用的一种方法是在 .pch文件中设置宽高,由于.pch是一个预编译文件,在全局都能访问到。html
#define ScreenHeight [UIScreen mainScreen].bounds.size.hight;ios
#define ScreenWidth [UIScreen mainScreen].bounds.size.width;windows
这个问题比较简单,彻底算不上技巧,可是有时咱们会忽略这个用法。就是给UIView设置背景图片。数组
_tabbarView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"tabbar_background.png"]];网络
咱们的图片是方形的,咱们想让它以圆形或者椭圆相似的形状在界面上显示。app
_image = [[UIImageView alloc]initWithFrame:CGRectMake(0,0,80,80)];async
_image.layer.cornerRadius = 40;//大小不一样,形状不一样ide
_image.clipsToBounds = YES;函数
如何获取主窗口的三种方法。ui
UIApplication *app=[UIApplication shareApplication];
1,UIWindow *window = app.keyWindow;
2,UIWindow *window = app.delegate.window;
3,UIWindow *window = [app.windows objectAtIndex:0];
固然咱们也可使用连写的方法:好比:UIWindow *window = [UIApplication shareApplication].delegate.window;
咱们有时候不当心修改了系统的API,或者其它的一些操做,出现了如下问题该怎么办?
错误信息:fatal error :file /Application ……….
Note: after modifying system headers, please delete the module cache at /Users …..
解决办法:前往/Users….这个文件夹,删除里面的文件,而后clean一下程序便可解决.
咱们如何让定时器暂停和开始,并非开启和关闭。
NSTimer *timer = [NSTimer sch……];
[timer setFireDate :[NSDate distantFuture]];//暂停
[timer setFireDate :[NSDate distantPass]]//开始
咱们弹出的键盘一般都是字母键盘,如何弹出数字键盘。
Textfiled.keyboardType = UIKeyboardTypeNumberPad;
在网络请求中,若是请求体中有汉字的话,请求会出错,怎样解决?
假设请求体为:NSString *urlString= @“http://v.juhe.cn/weather/index?cityname=北京”;
由于有汉字字符,请求会出错。处理办法:
urlString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
如何让咱们的图片放大不变形。
_image = [[UIImage imageNamed:@"a.png"]stretchableImageWithLeftCapWidth:20 topCapHeight:10];
ARC和非ARC混编。
若是你的项目中使用的是非ARC,导入的ARC代码的文件,须要在ARC模式的文件代码中加入-fobjc-arc标签
若是你的项目中使用的是ARC模式,则为非ARC模式的代码文件加入-fno-objc-arc标签
添加标签方法:target->build phases->compile sources ,双击对应的 .m文件,在弹出框中输入标签。
在自定义xib中cell的时候,UIImageView的图形跟定义的大小不匹配,可能按照原图片显示。
可能出现的问题是:UIImageView的命名为imageView,这个名字和系统的名字冲突,图片不能按预期的显示。
uitableview代理不调用。
常见的是没有设置代理。
还有一种状况是继承错误,通常来讲是继承UIViewController,若是继承关系写错,代理方法不会调用。我当时还出现了一下错误。
Two-stage rotation animation is deprecated. This application should use the smoother single-stage animation
如何找到xib上的view,可能有多个,能够用数组接收。
NSArray *nib = [[NSBundle mainBundle]loadNibNamed:@"CustomView" owner:self options:nil];
//获得第一个UIView
UIView *tmpCustomView = [nib objectAtIndex:0];
CGRect rect = [str boundingRectWithSize:CGSizeMake(300, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]} context:nil];
在UIButton上添加一个UIView,会使得UIButton的点击事件不能响应,解决办法是将UIView的可交互性改成NO.
若是界面中有ScrollView,而且界面中有导航条,视图控制器会默认给scrollview设置一个64偏移。
咱们可使用self.automaticallAdjustsScrollViewInsets = NO,scrollview不会偏移。
tabbar高度49,导航加状态栏高度64.
NSLog(@"%s",__FUNCTION__);
//字面量基本写法:
// NSString *str = @"123";
// NSDictionary *dict = @{@"name":@"wyg",@"age":@"12",@"sex":@"boy"};
// NSArray *arr = @[@"1",@"2"];
// NSString *st = arr[1];
// NSNumber *intNumber = @123;
// NSNumber *boolNumber = @NO;
将导航控制器中,视图从下面的坐标设为(0,0)
if ([self respondsToSelector:@selector(setEdgesForExtendedLayout:)]) {
self.edgesForExtendedLayout = UIRectEdgeNone;
}
父视图透明度对子视图无效设置:
maskView.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:0.4];
UITextField动态监听值变化:
[myTextField addTarget:self action:@selector(textFieldChange:) forControlEvents:UIControlEventEditingChanged];
-(void)textFieldChange:(UITextField *)textField
{
NSLog(@"print:%@",textField.text);
}
这段代码,本身体会
dispatch_async(dispatch_get_main_queue(), ^{
totalArray = arrayRes;
[addressbookTable reloadData];
});
IQKeyboardManager将Done改成完成,而且去掉中间占位提示符
[[IQKeyboardManager sharedManager]setToolbarDoneBarButtonItemText:@"完成"];
[[IQKeyboardManager sharedManager] setShouldShowTextFieldPlaceholder:NO];
iPhone5是32位系统,iPhone5以上位64位系统,若是数字位数比较多,例如一个精度比较高的时间戳,在处理数据的时候,在iPhone5上可能到致使问题。
建立Podfile:
touch Podfile
安装文件:
pod install --verbose --no-repo-update
Podfile文件样式:
platform :ios, '8.0'
inhibit_all_warnings!
use_frameworks!
target :'Kyw' do
pod 'AFNetworking', '~> 3.1.0'
pod 'MJRefresh', '~> 3.1.0'
pod 'MJExtension', '~> 3.0.10'
pod 'RESideMenu', '~>4.0.7'
pod 'TAKUUID', '~>1.1.0'
pod 'IQKeyboardManager', '~> 3.3.6'
pod 'MBProgressHUD', '~> 0.9.2'
pod 'BlocksKit', '~> 2.2.5'
pod 'LTNavigationBar', '~> 2.1.6'
pod 'Masonry', '~> 1.0.0'
pod 'UMengAnalytics'
end
在导入charts3.0图像库,x轴的数据自定义:
首先遵照IChartAxisValueFormatter代理;
添加(_lineView).xAxis.valueFormatter = self;
实现代理方法:
- (NSString *)stringForValue:(double)value axis:(ChartAxisBase *)axis
{
return arrayX[(int)value % arrayX.count];
}
获取请求的header
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html", @"image/gif", nil];
[manager GET:@"http://meinian.cn/createimage.aspx" parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
NSHTTPURLResponse *res = (NSHTTPURLResponse *)task.response;
NSLog(@"%@",[res allHeaderFields]); } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { NSLog(@"error:%@",error.description); }];