iOS 开发小技术点
2016-01-26 20:40
453 查看
判断scrollView滑动方向
手势添加步骤《轻拍手势为列》
改变字体大小填满label
内容模式等比例缩小放大,多余的剪掉
控件内容高度自适应
行间距
在段落显示中显示不完时,设置省略号显示的位置
在View中做Controller的操作时可以通过响应者链来找
图片呼吸效果
先遵循UIScrollViewDelegate协议 - (void)scrollViewDidScroll:(UIScrollView *)scrollView{ static float newx = 0; static float oldx = 0; newx= self.contentView.scrollView.contentOffset.y ; if (newx != oldx ) { if (newx > oldx) { [UIView animateWithDuration:.5 animations:^{ self.tabBerView.frame = CGRectMake(0, HXHeight, HXWidth, 49); }]; }else if(newx < oldx){ [UIView animateWithDuration:.5 animations:^{ self.tabBerView.frame = CGRectMake(0, HXHeight-49, HXWidth, 49); }]; } oldx = newx; } }
手势添加步骤《轻拍手势为列》
1.遵循协议 UIGestureRecognizerDelegate 2.创建手势 self.swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipe:)]; 4.打开控件的用户交互 self.contentView.userInteractionEnabled = YES; 5.设置手势的相关设置 self.swipe.direction = UISwipeGestureRecognizerDirectionRight;//设置清扫方向(向右) 6.设置代理 self.swipe.delegate= self; 7.添加到控件上 [self.contentView addGestureRecognizer:self.swipe]; 8.手势的方法实现 - (void)swipe:(UISwipeGestureRecognizer *)swipe { [self dismissViewControllerAnimated:YES completion:^{ }]; }
改变字体大小填满label
self.commentLabel.adjustsFontSizeToFitWidth = YES;
内容模式等比例缩小放大,多余的剪掉
self.contentImageView.clipsToBounds = YES; self.contentImageView.contentMode = UIViewContentModeScaleAspectFit; 等比例放大 self.contentImageView.contentMode = UIViewContentModeScaleAspectFill; self.contentImageView.clipsToBounds = YES;
控件内容高度自适应
CGSize size = CGSizeMake(self.HXTitleLabel.frame.size.width, 0); NSDictionary *dic = @{NSFontAttributeName:[UIFont systemFontOfSize:23.5]};//这里注意设置的字体要和其他地方设置该控件的字体大小保持一致 CGRect rect = [text.life_title boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:dic context:nil]; CGRect frame = self.HXTitleLabel.frame; frame.size.height = rect.size.height; self.HXTitleLabel.frame = frame;
行间距
CGFloat heih = 20; NSString * cLabelString = @" 这是测试UILabel行间距的text。这是测试UILabel行间距的text。\n 这是测试UILabel行间距的text。\n 这是测试UILabel行间距的text。这是测试UILabel行间距的text。这是测试UILabel行间距的text。这是测试UILabel行间距的text。"; UILabel * cLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, heih, 280, 200)]; cLabel.numberOfLines = 0; cLabel.font = [UIFont fontWithName:fontName size:16]; cLabel.textColor = [UIColor grayColor]; NSMutableAttributedString * attributedString1 = [[NSMutableAttributedString alloc] initWithString:cLabelString]; NSMutableParagraphStyle * paragraphStyle1 = [[NSMutableParagraphStyle alloc] init]; [paragraphStyle1 setLineSpacing:8]; [attributedString1 addAttribute:NSParagraphStyleAttributeName value:paragraphStyle1 range:NSMakeRange(0, [cLabelString length])]; [cLabel setAttributedText:attributedString1]; [cLabel sizeToFit]; [self.view addSubview:cLabel];
在段落显示中显示不完时,设置省略号显示的位置
self.contentLabel.lineBreakMode = NSLineBreakByTruncatingTail;
在View中做Controller的操作时可以通过响应者链来找
通过View找viewController - (UINavigationController *)findViewController:(UIView *)sourceView { id target= sourceView; while (target) { target = ((UIResponder *)target).nextResponder; if ([target isKindOfClass:[UINavigationController class]]) { break; } } return target; } 用的地方 HXFriendDetController *det = [[HXFriendDetController alloc] init]; UINavigationController *viewController = [self findViewController:self]; [viewController pushViewController:det animated:YES];
图片呼吸效果
//呼吸效果定时器 self.animationTimer = [NSTimer scheduledTimerWithTimeInterval:7.f target:self selector:@selector(animationView:) userInfo:nil repeats:YES]; - (void)animationView:(NSTimer *)timer { CGAffineTransform transform = self.backgImageView.transform; [UIView animateWithDuration:5.f animations: ^ { self.backgImageView.transform = CGAffineTransformMakeScale(1.4f, 1.4f); }]; [UIView animateWithDuration:5.f animations:^ { self.backgImageView.transform = transform; }]; }
相关文章推荐
- iOS 根据字符串数目,自定义Label等控件的高度
- iOS崩溃堆栈符号化,定位问题分分钟搞定!
- 【转】使用Xcode和Instruments调试解决iOS内存泄露
- iOS-nil,Nil,NULL的区别
- iOS 最新证书生成及导出p12文件和友盟的推送上传文件
- iOS选择相片优化
- iOS发布应用程序
- 从今天开始把博客替代笔记吧
- iOS开发实现Label中多颜色多字体
- iOS文字实现超链接
- 解决iOS键盘弹出遮挡输入框问题
- iOS安全-测试内容
- IOS 实现Button长按放大 并且可以移动互换位置
- IOS之ipone访问限制密码忘记解决办法1。
- iOS中的.h,.m,.mm,.cpp等区别
- ios 浅析MVVM模式
- iOS-@autoreleasepool-内存的分配与释放
- iOS_导入libxml2.2框架后,找不到<libxml/tree.h>的解决办法
- iOS开发,图片制作水印,图片裁剪,图片条纹背景,图片截图,以及将图片成文件存储。基于Quartz2D技术
- termios结构体