ios-新浪微博开发-14(新特性2)
2015-09-18 20:10
567 查看
在上次的基础上进行代码的修改
#import "QHNewfeatureViewController.h" #define QHNewfeatureCount 4 @interface QHNewfeatureViewController ()<UIScrollViewDelegate> @property(nonatomic,weak)UIPageControl *pageControl; @end @implementation QHNewfeatureViewController - (void)viewDidLoad { [super viewDidLoad]; //1.创建一个scrollView UIScrollView *scrollView = [[UIScrollView alloc]init]; scrollView.frame = self.view.bounds; scrollView.delegate = self; [self.view addSubview:scrollView]; CGFloat scrollW = scrollView.width; CGFloat scrollH = scrollView.height; //2.添加图片到scrollView for (int i = 0; i < QHNewfeatureCount; i++) { UIImageView *imageView = [[UIImageView alloc]init]; imageView.width = scrollW; imageView.height = scrollH; imageView.y = 0; imageView.x = i *imageView.width; //显示图片 NSString *name = [NSString stringWithFormat:@"new_feature_%d",i+1]; imageView.image = [UIImage imageNamed:name]; [scrollView addSubview:imageView]; //如果是最后一个imageView 就往里面添加内容 if(i == QHNewfeatureCount - 1) { [self setupLastImageView:imageView]; } } #warning 默认情况下 scrollView 一创建出来 它里面就可能存在一些控件了 #warning 就算不主动添加一些控件到scrollView中 内部还还是可能会有一些控件 //3.设置scrollView的其他属性 //如果想要某个方向不能滚动 那么那个方向对应的储存数值传0 scrollView.contentSize = CGSizeMake(QHNewfeatureCount *scrollView.width, 0); //取出弹簧效果 scrollView.bounces = NO; scrollView.pagingEnabled = YES; scrollView.showsHorizontalScrollIndicator = NO; //4.设置pageControll UIPageControl *pageControl = [[UIPageControl alloc]init]; pageControl.numberOfPages = QHNewfeatureCount; //@property(nonatomic,retain) UIColor *pageIndicatorTintColor NS_AVAILABLE_IOS(6_0) UI_APPEARANCE_SELECTOR; //@property(nonatomic,retain) UIColor *currentPageIndicatorTintColor pageControl.currentPageIndicatorTintColor =[UIColor colorWithRed:0.98f green:0.38f blue:0.11f alpha:1.00f]; pageControl.pageIndicatorTintColor =[UIColor colorWithRed:0.74f green:0.74f blue:0.74f alpha:1.00f]; pageControl.centerX = scrollView.width *0.5; pageControl.centerY = scrollView.height - 50; [self.view addSubview:pageControl]; self.pageControl = pageControl; // 不用设置尺寸也可以显示 // pageControl.width = 100; // pageControl.height = 50; // pageControl.userInteractionEnabled = NO; /** *[UIColor colorWithRed:0.98f green:0.38f blue:0.11f alpha:1.00f];橙色 *[UIColor colorWithRed:0.74f green:0.74f blue:0.74f alpha:1.00f];灰色 */ } - (void)scrollViewDidScroll:(UIScrollView *)scrollView { // int page = scrollView.contentOffset.x/scrollView.width; // self.pageControl.currentPage = page; // QHLog(@"%ld",(long)self.pageControl.currentPage); double page = scrollView.contentOffset.x/scrollView.width; self.pageControl.currentPage = (int)(page + 0.5); } - (void)setupLastImageView:(UIImageView *)imageView { //开启用户交互 imageView.userInteractionEnabled = YES; //1.分享给大家(check box) UIButton *shareBtn = [[UIButton alloc]init]; [shareBtn setImage:[UIImage imageNamed:@"new_feature_share_false"] forState:UIControlStateNormal]; [shareBtn setImage:[UIImage imageNamed:@"new_feature_share_true"] forState:UIControlStateSelected]; [shareBtn setTitle:@"分享给大家" forState:UIControlStateNormal]; [shareBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; shareBtn.titleLabel.font = [UIFont systemFontOfSize:15]; shareBtn.width = 100; shareBtn.height = 30; shareBtn.centerX = imageView.width *0.5; shareBtn.centerY = imageView.height *0.6; [shareBtn addTarget:self action:@selector(shareClick:) forControlEvents:UIControlEventTouchUpInside]; [imageView addSubview:shareBtn]; //EdgeInsets:自切 背景色是一种很好的调试工具 //top left bottom right 会影响按钮里面的所有内容(里面的imageView 和 titleLabel) // shareBtn.contentEdgeInsets = UIEdgeInsetsMake(<#CGFloat top#>, <#CGFloat left#>, <#CGFloat bottom#>, <#CGFloat right#>); //这个只影响titlelabel 的属性 // shareBtn.titleEdgeInsets = UIEdgeInsetsMake(<#CGFloat top#>, <#CGFloat left#>, <#CGFloat bottom#>, <#CGFloat right#>) shareBtn.imageEdgeInsets = UIEdgeInsetsMake(0, -20, 0, 0 ); // shareBtn.titleEdgeInsets 内边距 // shareBtn.imageEdgeInsets // shareBtn.contentEdgeInsets //2.开始微博 UIButton *startBtn = [[UIButton alloc]init]; [startBtn setBackgroundImage:[UIImage imageNamed:@"new_feature_finish_button"] forState:UIControlStateNormal]; [startBtn setBackgroundImage:[UIImage imageNamed:@"new_feature_finish_button_highlighted"] forState:UIControlStateSelected]; startBtn.size = startBtn.currentBackgroundImage.size; startBtn.centerX = shareBtn.centerX; startBtn.centerY = imageView.height *0.75; [startBtn setTitle:@"开始微博" forState:UIControlStateNormal]; [imageView addSubview:startBtn]; } - (void)shareClick:(UIButton *)shareBtn { //状态取反 shareBtn.selected = !shareBtn.selected; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. }
相关文章推荐
- ios-新浪微博开发-13-新特性(1)
- iOS中消息的传递机制
- 苹果开发 笔记(77)NSJSONSerialization
- iOS数据解析之NSXMLParser
- xcode 6.4 启动虚拟机自动退出
- ios开发必备10款第三方类库
- 一些iOS常用的第三方库和控件
- iOS MKMapView简单介绍
- ios+phonegap跳转到任意界面
- xcode7,ios9 部分兼容设置 bitcode
- iOS—请求Web Service
- iOS数据解析之json
- xcode7 iOS9 问题大全及解决
- vmstat及iostat检查io问题
- 学习笔记--获取ios当前时间
- iOS 开发:绘制像素到屏幕
- TextField相关基础用法
- iOS --制作画板 --2
- iOS学习笔记28-JS执行过程分析
- Xcode 7 IOS9 问题大全及解决