备忘录
[self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:KCollectionViewCellID];
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:KCollectionViewCellID forIndexPath:indexPath];
======================================================================================
OS:图片平铺到屏幕
UIScrollView*scrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0,64, SCREEN_WIDTH, SCREEN_HEIGHT-64)];
scrollView.scrollEnabled=YES;
scrollView.showsHorizontalScrollIndicator = NO;
scrollView.scrollsToTop=YES;
scrollView.bounces=YES;
// 图片等比例缩放
float scale=image.size.width/SCREEN_WIDTH;
CGFloat imageViewH = image.size.height/scale;
UIImageView*KImageView=[[UIImageView alloc]init];
KImageView.image=image;
KImageView.userInteractionEnabled=YES;
KImageView.frame=CGRectMake(0, 0,SCREEN_WIDTH, imageViewH);
[scrollView addSubview:KImageView];
scrollView.contentSize= KImageView.bounds.size;
===================================================================
去除首位空格
NSString *content = [textView.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
去除首位空格和换行
NSString *content = [textView.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
=================================================================================
黑色蒙版增加到window上
UIButton *coverButton = [[UIButton alloc]initWithFrame:CGRectMake(0,coverViewH, SCREEN_WIDTH, SCREEN_HEIGHT - coverViewH)];
coverButton.backgroundColor = RGBA(0, 0, 0, 0.4) ;
[coverButton addTarget:self action:@selector(coverBtnAction) forControlEvents:UIControlEventTouchUpInside];
UIView *viewWindow = [[UIApplication sharedApplication].delegate window];
[viewWindow addSubview:coverButton];
[YWUserDefaults setBool:YES forKey:KShowGuide];[YWUserDefaults setBool:YES forKey:KShowGuide];
BOOL showFunction = [userDefaults boolForKey:@"showFunction"];
=================================================================================
一个控制器中包含切换视图
collectionView 和tableView
1:当数据初始化的时候同时给collection和tableview 填充数据
2: 在点击视图切换的时候让collection和tableview 各自隐藏和显示
3: 设置二者控制器的的位置保持一致
self.homeTableView.contentOffset = self.collectionView.contentOffset;
=================================================================================
IOS 圆形头像
//头像
UIImageView *headPicView = [[UIImageView alloc]init];
headPicView.backgroundColor = [UIColor whiteColor];
self.headPicView = headPicView;
headPicView.contentScaleFactor = [UIScreen mainScreen].scale;
headPicView.contentMode = UIViewContentModeScaleAspectFill;
self.headPicView.layer.borderColor =[[UIColor whiteColor] colorWithAlphaComponent:0.8f].CGColor;
[self addSubview:headPicView];
[self.headPicView sd_setImageWithURL:[NSURL URLWithString:user.headPicAddr]];
self.headPicView.frame = CGRectMake( (SCREEN_WIDTH- kHeadPic ) / 2, KHeaderH- kHeadPic - 10, kHeadPic, kHeadPic);
self.headPicView.clipsToBounds = YES;
self.headPicView.layer.cornerRadius = self.headPicView.bounds.size.width/2;
self.headPicView.layer.borderWidth = 2;
=================================================================================
UIViewController *viewCtl = self.navigationController.viewControllers[2];
[self.navigationController popToViewController:viewCtl animated:YES];
=================================================================================
常用代码
--计算文字尺寸
CGSize contentLabelSize = [_status.postContent textSizeWith:CGSizeMake(SCREEN_WIDTH - 20, MAXFLOAT)
=================================================================================
项目名称
$(TARGET_NAME)
=================================================================================
button相关操作
/ 创建
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(0.0f, 0.0f, 300.0f, 233.0f);
button.center = CGPointMake(160.0f, 140.0f);
// 设置aligment 属性
button.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
//button.titleLabel.textAlignment = UITextAlignmentCenter;
//设置title自适应对齐
button.titleLabel.lineBreakMode = UILineBreakModeWordWrap;
// 设置颜色和字体
[button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[button setTitleColor:[UIColor lightGrayColor] forState:UIControlStateHighlighted];
button.titleLabel.font = [UIFont boldSystemFontOfSize:24.0f];
// 添加 action
[button addTarget:self action:@selector(toggleButton:) forControlEvents: UIControlEventTouchUpInside];
//设置title
[button setTitle:@"On" forState:UIControlStateNormal];
[button setTitle:@"On" forState:UIControlStateHighlighted];
//设置背景
[button setBackgroundImage:baseGreen forState:UIControlStateNormal];
[button setBackgroundImage:altGreen forState:UIControlStateHighlighted];
// 用于测试的BOOL
isOn = NO;
=================================================================================
OS —— Attributes文字的操作,TextFiel框内文字颜色大小等改变
(2014-06-20 15:55:19)
转载▼
标签:
ios
分类: IOS相关
文本属性Attributes
1.NSKernAttributeName: @10 调整字句 kerning 字句调整
2.NSFontAttributeName : [UIFont systemFontOfSize:_fontSize] 设置字体
3.NSForegroundColorAttributeName :[UIColor redColor] 设置文字颜色
4.NSParagraphStyleAttributeName : paragraph 设置段落样式
5.NSMutableParagraphStyle *paragraph = [[NSMutableParagraphStyle alloc] init];
paragraph.alignment = NSTextAlignmentCenter;
6.NSBackgroundColorAttributeName: [UIColor blackColor] 设置背景颜色
7.NSStrokeColorAttributeName设置文字描边颜色,需要和NSStrokeWidthAttributeName设置描边宽度,这样就能使文字空心.
NSStrokeWidthAttributeName这个属性所对应的值是一个 NSNumber 对象(小数)。该值改变描边宽度(相对于字体size 的百分比)。默认为 0,即不改变。正数只改变描边宽度。负数同时改变文字的描边和填充宽度。例如,对于常见的空心字,这个值通常为3.0。
同时设置了空心的两个属性,并且NSStrokeWidthAttributeName属性设置为整数,文字前景色就无效果了
效果:
效果:
8. NSStrikethroughStyleAttributeName 添加删除线,strikethrough删除线
效果:
9. NSUnderlineStyleAttributeName 添加下划线
效果:
10. NSShadowAttributeName 设置阴影,单独设置不好使,必须和其他属性搭配才好使。
和这三个任一个都好使,NSVerticalGlyphFormAttributeName,NSObliquenessAttributeName,NSExpansionAttributeName
11.NSVerticalGlyphFormAttributeName
该属性所对应的值是一个 NSNumber 对象(整数)。0 表示横排文本。1 表示竖排文本。在 iOS 中,总是使用横排文本,0 以外的值都未定义。
效果:
12. NSObliquenessAttributeName设置字体倾斜。Skew 斜
效果:
13. NSExpansionAttributeName 设置文本扁平化
效果:
=================================================================================
自定义view的步骤
1.新建一个类 ,集成自UIVIew
2.实现 - (void)drawREct:(CGRect)rect方法,然后在这个方法中
(1)取得跟当前view相关联的图像上下文
(2)绘制绘制响应的图形内容
(3)利用图像上下文将绘制的所有内容渲染显示到view上面
为什么要实现drawRect:方法才能就爱你过绘图到view上
因为在drawRect:方法中才能取得跟view相关联的图像上下文
drawRect方法在什么时候被调用
当view第一次显示在屏幕上时(被加到UIWindow上显示出来)
调用view的setNeedDisplay 或者 setNeedsDisplayInRect: 时
=================================================================================
如果控制器之间的关系比较紧密一般用UINavigationController
如果控制器之间的关系不是很紧密可以是Modal
Modal 模态视图(视图弹出后,后一个视图不可点,通常模态视图是从下往上出现)
firstViewController *first = [[firstViewController alloc]init];
弹出方法
[self presentViewController:first animated:YES completion:^{
//弹出控制器视图之后所进行的操作.
NSLog(@"控制器视图已经完全弹出了");
}];
first 这个控制器视图是被强引用
通过presentViewController:first 这个方法 会讲first 这个控制器赋值给PresentedViewController
关闭方法
[self dismissViewControllerAnimated:YES completion:^{
//完全关闭了
NSLog(@"完全关闭后所进行的操作"); }];
//如果一个控制器是一个模态的形式出来的,可以调用该控制器以及改控制器的自控制器让控制器消失
[self.navigationController dismissViewControllerAnimated:YES completion:^{
//
}];
(void)prepareForSegue:(UIStoryBoardSegue *)segue sender:(id)sender {
//取出目标控制器
UINavigationController *nav = segue.destinationViewController;
//取出导航控制器的栈顶控制器
XXXController *xxx= (XXXController) nav.topVIewController;
xxx.name = @“ddd”;
}
}];
=================================================================================
NSRULConnection
发送请求给服务器(带上账号和密码)
常用类
NSURL :请求地址
NSURLRequest :一个NSURLRequest 对象就代表一个请求,它包含的信息有
1.一个NSURL对象
2.请求方法,请求头,请求体
3.请求超时
4……
NSMutableURLRequest:NSURLRequest 的子类
NSRULConnection
负责发送请求,建立客户端和服务器的连接
负责NSRULREquest的数据给服务器,并收集来自服务的响应数据
GET请求:请求行\请求头 (IOS 省略 ,安卓不可省略)
步骤:
创建一个NSURL对象,设置请求路径
传入NSURL创建一个NSURLRequest对象,设置请求头和请求体
使用NSURLConnection 发送NSURLRequest
什么是json
json是一种轻量级的数据格式,一般用作数据交互
服务返回数据给客户端的数据,一般都是json格式或者xml格式(文件下载除外)
json的格式和oc中的字典和数组很像
{“name” :”jack”,”age”:10}
{“names” : [“jack”,”rose”,”jim”]}
json的标准格式 Key 必须要用双引号
json 转为换oc
json oc
大括号{ } NSDictionary
中括号[] NSArray
双引号” “ NSString
数字 10 10.8 NSNumber
json解析方案
1第三方框架:JSONKit,SBJson.TouchJSON(性能从左道右,越差)
2 苹果原生(自带)NSJSONSerialization(性能最好) ——v
json - oc
+ (id)JSONObjectWithData:(NSData*)data options:(NSJSONReadingOptions)opt error:(NSError *)error
oc - json数据
+(NSData *)datawithJSONObject:(id)obj options:(NSJSONWritingOptions)opt error:(NSError *)error
=================================================================================
Http 协议(HyPertext Transfer Protocol 超文本传输协议)
常见的协议:Http(超文本传输协议,用作远程的网络资源访问,格式:http://),file(访问的是本地计算机上的资源 主机地址省略 格式是:file://),
),mailto(访问的是电子邮件的地址,格式是mailto:)ftp(访问的是共享主机的文件资源格式)
http协议是规定客户端和服务器之间的数据传输格式,让客户端和服务器能有效的进行数据沟通
客户端 <- >服务器交互
http协议传递的什么格式的数据给服务器
服务器返回什么格式的数据给客户端.
优点:
简单快捷
因为http协议简单,所以http服务器的程序规模小,因而通讯速度很快
灵活
http允许传输任意类型的数据
http0.9和1.0 使用非持续连接
限制每次连接只处理一个请求,服务器对客户端的请求做出响应后,马上断开连接,这种方式可以节约传输时间.
http通信过程 - 请求(请求行,请求头,请求体)
http协议规定:1个完整的由客户端发给服务器的http]请求中包含以下内容
get /MjServer/resources/images/1.jpg HTTP/1.1
请求行: 包含请求方法/请求资源路径,http协议版本.
请求头:包含了对客户端的环境描述/客户端请求的主机地址等信息.
Host:192.168.1.105:8080 //客户端想访问服务器主机地址
User-Agent :Mozilla/5.0 (Macintosh;Intel MacOS X 10.9 ) Firefox/30.0
客户端的类型,客户端的软件环境.
Accept : text/teml , */* //客户端所能接收的客户类型.
Accept-Language :zh-cn 客户端的语言环境.
Accept- Encoding :gzip //客户端支持的数据压缩格式
存放格式:(key —— value )
请求体: 客户端发送给服务器的具体数据,比如文件数据.
查看工具firebug
火狐插件:firbug 可拦截所有的http请求
网络 — 监控所有的http请求
工具 - 附加组件
1 在浏览器中录入rul
2 网络
HTTP通信过程 — 响应
客户端向服务器发送请求,服务器应当做出响应,即返回数据给客户端
http协议规定:一个完整的http响应中包含以下内容
状态行(响应行):包含了htp协议版本,状态码,状态英文名称.
http;/1.1 200 ok
响应头:
server: apache-coyote/1.1 //服务器类型
content-Type :image/jpeg //返回数据的类型
Content-Length:56811(字节) //返回数据的长度
Date //响应的时间
实体内容 : 服务器返回给客户端的具体数据,比如文件数据
客户端 - [请求行,请求头,请求体] >>>服务器
服务器 - [状态行,响应头,实体内容] >>>客户端
响应状态码
200 ok 请求成功
400 BadRequest 客户端请求的语法错误,服务器无法解析
404 NotFound
500 Internal Server Error
=================================================================================
浙公网安备 33010602011771号