// The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization.
self.title = @"主流公司指数";
mainView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
mainView.delegate = self;
[self.view addSubview:mainView];
UIBarButtonItem *reloadItem = [[UIBarButtonItem alloc] initWithTitle:@"重新加载" style:UIBarButtonItemStylePlain target:self action:@selector(reloadItem_click)];
self.navigationItem.rightBarButtonItem = reloadItem;
/*mainView = [[UIScrollView alloc] initWithFrame:CGRectMake(0.0, 0.0, self.view.frame.size.width, 400)];
mainView.directionalLockEnabled = YES;
mainView.pagingEnabled = YES;
mainView.backgroundColor = [UIColor blueColor];
mainView.showsVerticalScrollIndicator = NO;
mainView.showsHorizontalScrollIndicator = NO;
mainView.delegate = self;
CGSize newSize = CGSizeMake(self.view.frame.size.width * 2, self.view.frame.size.height);
[mainView setContentSize:newSize];
[self.view addSubview:mainView];
pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(0.0, 401, self.view.frame.size.width, 80)];
pageControl.hidesForSinglePage = YES;
pageControl.userInteractionEnabled = NO;
pageControl.backgroundColor = [UIColor redColor];
[self.view addSubview:pageControl];
page1=[[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, self.view.frame.size.width, self.view.frame.size.height)];
page1.backgroundColor=[UIColor redColor];
[mainView addSubview:page1];
page2=[[UIView alloc] initWithFrame:CGRectMake(self.view.frame.size.width, 0.0, self.view.frame.size.width, self.view.frame.size.height)];
page2.backgroundColor=[UIColor blueColor];
[mainView addSubview:page2]; //[mainView setBackgroundColor:[UIColor redColor]];
*/
}
return self;
}
/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
/*BfViewController *bf = [[BfViewController alloc]init];
[self.view addSubview:bf.view];
[bf setTopicText:@"test"];
[bf setMarkText:@"mark"];
*/
/*[super viewDidLoad];
waitView = [[UIWaitingView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
[self.view addSubview:waitView];
[self.view bringSubviewToFront:waitView];
[waitView starActivityLoading];
[waitView setLoadingLabel:@"正在加载数据..."];
*/
//[bf release];
//[bf2 release];
}
- (void)viewDidAppear:(BOOL)animated{
NSLog(@"CompanyController.viewDidAppear");
[super viewDidAppear:animated];
if(companyList==nil){
[[WaitDialog sharedWaitDialog] setLoadingLabel:@"链接网络中.."];
timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(fetchData) userInfo:nil repeats:NO];
}
}
-(void)fetchData{
[self removeAllView];
companyList = [JSONParser loadData:@"http://3g.wapzq.com/odds/json/company.jsp" isAllValues:NO valueForKey:@"list"];
//NSLog(@"companyList:%@",arr);
//[waitView endActivityLoading];
//[waitView removeFromSuperview];
//[[WaitDialog sharedWaitDialog]endShowLoading];
[[WaitDialog sharedWaitDialog]setLoadingLabel:@"正在构造界面..."];
[self makeView];
}
-(void)removeAllView{
for(UIView *subView in [mainView subviews]){
[subView removeFromSuperview];
}
}
-(void)makeView{
[[WaitDialog sharedWaitDialog]endShowLoading];
if(companyList==nil||[companyList count]==0){
UILabel *nullData = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, self.view.frame.size.width-20, 40)];
nullData.text = @"暂时没有数据";
nullData.backgroundColor = [UIColor clearColor];
nullData.font = [UIFont systemFontOfSize:20];
[mainView addSubview:nullData];
}else{
int count = [companyList count];
int i = 0;
int x = 10;
int y = 10;
int width = self.view.frame.size.width / 2 - 40;
int height = 30;
int contentHeight = (height+y*2)*count/2;
CGSize newSize = CGSizeMake(self.view.frame.size.width,contentHeight);
[mainView setContentSize:newSize];
for(i = 0; i < count/2; i++){
NSArray *company = [companyList objectAtIndex:i];
// NSLog(@"index %d has %@.",i, [companyList objectAtIndex:i]);
//NSLog(@"company.id:%@,name:%@",[company valueForKey:@"cid"],[company valueForKey:@"name"]);
UIButton *btn = [[UIButton buttonWithType:UIButtonTypeRoundedRect]retain];
btn.frame = CGRectMake(x, y, width, height);
btn.backgroundColor = [UIColor clearColor];
//UIButton*btn=[[UIButton alloc]initWithFrame:CGRectMake(x, y, width, height)];
//btn.backgroundColor = [UIColor colorWithRed:0.52 green:0.09 blue:0.07 alpha:1];
//[btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[btn setTitle:[company valueForKey:@"name"] forState:UIControlStateNormal];
//btn.titleLabel.font = [UIFont systemFontOfSize:19];
[btn addTarget:self action:@selector(selectCompany:) forControlEvents:UIControlEventTouchUpInside];
[mainView addSubview:btn];
[btn release];
y+=height+10;
}
x = self.view.frame.size.width /2 +10;
y = 10;
for(i;i<count;i++){
NSArray *company = [companyList objectAtIndex:i];
UIButton *btn = [[UIButton buttonWithType:UIButtonTypeRoundedRect]retain];
btn.frame = CGRectMake(x, y, width, height);
//[btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[btn setTitle:[company valueForKey:@"name"] forState:UIControlStateNormal];
//btn.titleLabel.font = [UIFont systemFontOfSize:19];
[btn addTarget:self action:@selector(selectCompany:) forControlEvents:UIControlEventTouchUpInside];
[mainView addSubview:btn];
[btn release];
y+=height+10;
}
}
}
分享到:
相关推荐
UIScrollView有自己默认的滚动条,可设置隐藏和显示,但是有时候这个默认的滚动条没办法满足我们的需求,那这时候只能通过自定义来实现了。 实现自定义滚动条需要解决的主要问题是: 在scrollview滚动的过程中如何...
自定义UIScrollView实现全屏滑动显示不同控制器的LBPScrollSegmentView 封装网络访问类AFNetPackage,具备检查网络状态、JSON方式获取数据、xml方式获取数据、post、get、delete、文件下载、文件上传等功能 ...
UIScrollView控件实现图片轮播 一、实现效果 实现图片的自动轮播 二、实现代码 storyboard中布局 代码: 代码如下: #import “YYViewController.h” @interface YYViewController () @property (weak, ...
自定义UIScrollView, 内嵌UIImageView, 可从网络拉取数据进行填充,方便结合SDWebImage等第三方库进行扩展。本例仅仅是一个小Demo, 所用图片均在ImageSet中, 并未从网络拉取(原版OC实现了网络拉取).同时实现了...
SSRollingButtonScrollView是一个自定义UIScrollView子类,具有UIButtons的无限循环滚动的功能。 SSRollingButtonScrollView的用户至少必须提供按钮标题数组并指定布局样式(水平滚动或垂直滚动)。 通过实现可...
GHWXcodeExtension:Xcode源代码编辑器扩展插件,实现功能有四个,一。初始化自定义视图,UICollectionViewCell,UITableViewCell,viewController,自动删除无用代码和添加代码;二。为属性自动添加懒惰加载代码,...
掘金APP个人中心页样式、微博发现页ScrollView嵌套样式、简书APP个人中心页样式代码地址GitHub:https://github.com/wsl2ls/iOS_TipsiOS的一些示例,不定时更新~目录1、暗黑模式2、AppleID登录应用3、AVFoundation...
从技术上来讲,这项目包括很多常用的技巧,包括: 1. 如何通过 NSURLConnection + ...7. 主菜单没有用tableView, 而是用 UIView + UIScrollView + JSON + 自定义的Tap 事件, 这个过程用了Expandad 的 MVC 架构
好了,说正事,对于ios开发我没接触,不是很了解,百度了半天,差不多就是UIScrollView的把。如果不对,请指证。具体什么效果呢,我刚才拿朋友的iphone手机看了下,iphone的设置界面,第一个列表往下拉可以继续滚,...
2) 在商城页面,用UIScrollView 滚动视图,实现轮播图 3) 用自定义的cell进行组装UITableView 表格视图, 展示各种各样的水果图片和价格 4) 进入水果详情页,采用AVPlayerViewController进行播放科普视频,并采用...
1.可自定义修改菜单栏字体颜色、大小 2.滚动视图带有缓存功能,当多个视图控制器加在UIScrollView上会占用很多内存,因此加入了缓存策略 3.实现类似UITableView的代理和数据源代理,...
1.可自定义修改菜单栏字体颜色、大小 2.滚动视图带有缓存功能,当多个视图控制器加在UIScrollView上会占用很多内存,因此加入了缓存策略 3.实现类似UITableView的代理和数据源代理,...
2.在mainstoryboard中拖入ScrollView和Page Control(也可以代码写,或者是自定义xib) 设置page control的 Current Page属性,决定轮播的当前页显示的颜色 3.接下来就是正式代码了 //(1)将需要展⽰的内容添加到...
实现可以自定义翻页长度的UIScrollView。对于一般的ScrollView,如果把paging属性设置为true,那么每次翻页的长度都只是一个尺寸,就是一个页面(page)的宽度。这份代码可以任意设定ScrollView的翻页尺寸,比如在...
UIScrollview 的分类和实现,只需几行代码。 它开箱即用! 要求 MAPullToRefresh使用 ARC 并且需要 iOS 7.0+。 适用于 iPhone 和 iPad。 安装 手动的 将文件夹MAPullToRefresh复制到您的项目中。 用法 下拉刷新只需...
iOS实现扩展了默认的UIScrollView组件,而Android实现是自定义的,旨在与iOS api提供有限的奇偶校验。 支持以下道具: Struts 默认 描述 scrollEnabled true 如果为false,则无法通过触摸交互滚动视图。 ...
如果需要模糊背景,可以在自定义的 UIView 中先添加模糊背景,再添加 UIScrollView,继而在 UIScrollView 中添加图片容器,这个容器就是要显示的图片的 superView,代码一目了然: - (void)setup { self.frame = ...
来源:Licence:MIT平台:iOS设备:iPhone... 小编注:代码不是用UIPicker来实现,而是利用UIScrollView来实现的,所以,严格意义上来说,不算是自定义UIPicker。 Code4App编译测试,适用环境:Xcode 4.3, iOS 5.0。
代码地址GitHub:https://github.com/wsl2ls/iOS_Tips目录:1、暗黑模式2、AppleID登录应用3、AVFoundation相关3.1、AVFoundation 高仿微信相机拍摄和编辑3.2、AVFoundation 人脸检测3.3、AVFoundation 实时滤镜3.4...