`
gekie
  • 浏览: 155321 次
  • 性别: Icon_minigender_1
  • 来自: 海口
社区版块
存档分类
最新评论

iPhone开发乱乱记

阅读更多

自由布局,UIButton样式,下阴影,按钮事件。

导航栏rightBarButtonItem增加UISegmentedControl控件。

 

 

 

 

#import <QuartzCore/QuartzCore.h>
#import "LeagueController.h"
#import "WaitDialog.h"
#import "JSONParser.h"
#import "FunUtil.h"

@implementation LeagueController
@synthesize selectDate;
@synthesize flag;
@synthesize topToolBar;
@synthesize mainView;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        
    }
    return self;
}
-(id)initWithDate:(CFGregorianDate) date{
	self = [super initWithNibName:nil bundle:nil];
	if(self){
		self.selectDate = date;
		self.title = @"联赛选择";
	
		NSArray *buttonNames = [NSArray arrayWithObjects:@"所有", @"一级", @"二级", nil];
		topToolBar = [[UISegmentedControl alloc] initWithItems:buttonNames];
		[topToolBar setFrame:CGRectMake(1, 1, 120, 30)];
		topToolBar.selectedSegmentIndex = 0;
		topToolBar.segmentedControlStyle = UISegmentedControlStyleBar;
		[topToolBar addTarget:self action:@selector(selectFlag:) forControlEvents:UIControlEventValueChanged];
		UIBarButtonItem *segButton = [[UIBarButtonItem alloc] initWithCustomView:topToolBar];
		self.navigationItem.rightBarButtonItem = segButton; 
		
		self.mainView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
		[self.view addSubview:mainView];
		[segButton release];
		self.flag = 0;
	}
	return self;
}
-(void)removeAllView{
	for(UIView *subView in [self.mainView subviews]){
		[subView removeFromSuperview];
	}
}
- (void)viewDidAppear:(BOOL)animated{
	[super viewDidAppear:animated];
	self.mainView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
	[[WaitDialog sharedWaitDialog] setLoadingLabel:@"加截数据..."];
	[NSThread detachNewThreadSelector:@selector(fetchData) toTarget:self withObject:nil];
}
-(void)selectFlag:(UISegmentedControl *)Seg{
	int index = Seg.selectedSegmentIndex;
	self.flag = index;
	[NSThread detachNewThreadSelector:@selector(fetchData) toTarget:self withObject:nil];
}
-(void) fetchData{
	NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
	[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
	NSString *date = [NSString stringWithFormat:@"%d-%d-%d",selectDate.year,selectDate.month,selectDate.day];
	NSString *dataURL =@"";
	NSArray *data = [JSONParser loadData:dataURL isAllValues:NO valueForKey:@"list"];
	[self performSelectorOnMainThread:@selector(makeView:) withObject:data waitUntilDone:NO];
	[pool release];
}
-(void)makeView:(NSArray*)data{
	[self removeAllView];
	[[WaitDialog sharedWaitDialog]endShowLoading];
	if(data == nil || [data 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 boldSystemFontOfSize:20];
		[self.mainView addSubview:nullData];
	}else{
		int count = [data count];
		int i = 0;
		int x = 10;
		int y = 10;
		int cols = 3;
		int width = self.view.frame.size.width/cols -20;
		int height = 30;
		int contentHeight = (height+y*2)*(count/cols);
		
		int c = count/cols+1;
		for(i = 0;i<c;i++){
			NSArray *league = [data objectAtIndex:i];
			UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
			btn.layer.cornerRadius = 5;
			btn.layer.shadowOffset =  CGSizeMake(3, 5);
			btn.layer.shadowOpacity = 0.8;
			btn.layer.shadowColor =  [UIColor blackColor].CGColor;
			btn.frame = CGRectMake(x, y, width, height);
			btn.backgroundColor =  [FunUtil colorWithHexString:[league valueForKey:@"color"]];
			[btn setTitleColor:[UIColor whiteColor ]forState:UIControlStateNormal];
			[btn setTitle:[league valueForKey:@"cnName"] forState:UIControlStateNormal];
			[btn setTag:[[league valueForKey:@"lid"] intValue]];
			[btn addTarget:self action:@selector(selectLeague:) forControlEvents:UIControlEventTouchUpInside];
			[btn addTarget:self action:@selector(buttonDown:) forControlEvents:UIControlEventTouchDown];
			[self.mainView addSubview:btn];
			y+=height+10;
		}
		
		contentHeight = (height+10)*c+10;
		CGSize newSize = CGSizeMake(self.view.frame.size.width, contentHeight);
		[self.mainView setContentSize:newSize];
	}
}
-(void)selectLeague:(UIButton*)sender{
	[sender setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
	sender.layer.shadowOffset =  CGSizeMake(3, 5);
	sender.layer.shadowOpacity = 0.8;
	sender.layer.shadowColor =  [UIColor blackColor].CGColor;
}
-(void)buttonDown:(UIButton*)sender{
	[sender setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];
	sender.layer.shadowOffset =  CGSizeMake(0,0);
	sender.layer.shadowOpacity = 1;
	sender.layer.shadowColor =  [UIColor blackColor].CGColor;
}
#pragma mark TableViewDataSource Methods

- (void)dealloc {
	[topToolBar release];
	[mainView release];
    [super dealloc];
}


@end

 

  • 大小: 242.6 KB
分享到:
评论

相关推荐

    iPhone开发实战.pdf

    iPhone开发实战 iPhone开发 iPhone iPhone4 iPhone开发实战 iPhone开发 iPhone iPhone4

    Iphone开发系列源码——Iphone主题源码

    Iphone开发系列源码——Iphone主题源码Iphone开发系列源码——Iphone主题源码Iphone开发系列源码——Iphone主题源码Iphone开发系列源码——Iphone主题源码Iphone开发系列源码——Iphone主题源码Iphone开发系列源码...

    iPhone开发基础教程电子书

    这里推荐两本书《objective-c基础教程》和《iphone开发基础教程》,这两本都是圣经级的巨作,我相信每一个iphone开发人员应该都不会错过这两本书的。  等你xcode和objective-c摸熟之后,或者说,上面提到的那两...

    Iphone开发系列源码——iPhone版Wordpress源代码

    Iphone开发系列源码——iPhone版Wordpress源代码Iphone开发系列源码——iPhone版Wordpress源代码Iphone开发系列源码——iPhone版Wordpress源代码Iphone开发系列源码——iPhone版Wordpress源代码Iphone开发系列源码...

    iPhone开发基础教程-PDF版

    iPhone开发,iPhone开发教程,iPhone开发基础教程PDF版

    Iphone开发系列源码——Image图片缩放随着手指

    Iphone开发系列源码——Image图片缩放随着手指Iphone开发系列源码——Image图片缩放随着手指Iphone开发系列源码——Image图片缩放随着手指Iphone开发系列源码——Image图片缩放随着手指Iphone开发系列源码——Image...

    iPhone开发基础教程

    《iPhone开发基础教程》内容完整丰富,具有较强的通用性,编程领域中各层次读者都能通过《iPhone开发基础教程》快速学习iPhone开发,提高相关技能。iPhone 是一种全新的移动平台,苹果公司为它推出了强大的软件开发...

    iPhone开发入门到精通视频教程

    资源名称:iPhone开发入门到精通视频教程资源目录:【】iOS开发源码系列---工具【】iOS开发源码系列---应用【】iOS开发源码系列---游戏【】iOS开发源码系列---类库与框架【】iOS开发真机测试与发布【】iOS开发视频...

    轻松学iPhone开发

    轻松学iPhone共分3篇。第1篇介绍iPhone的发展、iPhone开发环境以及开发工具的安装过程、iPhone Simulator模拟器

    iphone开发实战

    本书全面探讨了iPhone平台的两种编程方式——Web开发和SDK编程。全在Web开发方面,分别介绍了三个iPhone Web库,即WebKit、iUI和Canvas,并讨论了Web开发环境Dashcode,最后阐述Web应用程序的调试。在SDK开发方面,...

    iPhone游戏开发

    iPhone游戏开发iPhone游戏开发iPhone游戏开发iPhone游戏开发iPhone游戏开发iPhone游戏开发iPhone游戏开发iPhone游戏开发iPhone游戏开发iPhone游戏开发

    IPhone开发

    iphone开发秘籍,移动手机开发,参照软件开发应用

    iPhone开发实战

    iPhone开发实战

    iPhone3开发基础教程

    这是一本很不错的iphone开发入门级教程

    深入浅出iPhone开发(清晰版,内含中英2个版本的书)

    知名的Head First系列丛书之一,风格与其他Head First系列一脉相承,一定能让读者轻松学会iPhone开发,《深入浅出iPhone开发》是针对iPhone开发的初学者设计的,以几个应用实例的开发为例,循序渐进地对iPhone开发的...

    深入浅出iPhone开发

    《深入浅出iPhone开发》,本书是针对iPhone开发的初学者设计的,以几个应用实例的开发为例,循序渐进地对iPhone开发的各个方面进行了讲解。

    Iphone开发系列源码——多功能播放器源码

    Iphone开发系列源码——多功能播放器源码Iphone开发系列源码——多功能播放器源码Iphone开发系列源码——多功能播放器源码Iphone开发系列源码——多功能播放器源码Iphone开发系列源码——多功能播放器源码Iphone开发...

    iphone开发视频教程

    资源名称:iphone开发视频教程资源目录:【】iphone开发视频教程第1集 Mac.OS.X,Cocoa,Touch,Objective-C【】iphone开发视频教程第2集 各种基础的类,功能,对象和实例的介绍【】iphone开发视频教程第3集 如何创建你...

    Iphone开发系列源码——星级评价实现代码

    Iphone开发系列源码——星级评价实现代码Iphone开发系列源码——星级评价实现代码Iphone开发系列源码——星级评价实现代码Iphone开发系列源码——星级评价实现代码Iphone开发系列源码——星级评价实现代码Iphone开发...

    [iphone.开发书籍 高清PDF]iphone3开发基础教程.part3

    [iphone.开发书籍 高清PDF]iphone3开发基础教程.part3

Global site tag (gtag.js) - Google Analytics