原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://xys289187120.blog.51cto.com/3361352/786930
IOS 入门开发之使用XCODE4制作静态库详解
- #import <UIKit/UIKit.h>
- @interface MyView : UIView
- @end
- #import "MyView.h"
- @implementation MyView
- - (id)initWithFrame:(CGRect)frame
- {
- //初始化视图位置
- self = [super initWithFrame:frame];
- if (self) {
- }
- return self;
- }
- - (void)drawRect:(CGRect)rect
- {
- //这里创建一个图片视图
- UIImage *image=[[UIImage alloc]initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://www.google.com.hk/intl/zh-CN/images/logo_cn.png"]]];
- [image drawInRect:CGRectMake(0, 0,self.frame.size.width , self.frame.size.height)];
- [image release];
- }
- -(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
- {
- //点击视图后打开网页
- [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.baidu.com"]];
- }
- @end
- #import "ViewController.h"
- #import "MyView.h"
- @implementation ViewController
- - (void)didReceiveMemoryWarning
- {
- [super didReceiveMemoryWarning];
- // Release any cached data, images, etc that aren't in use.
- }
- #pragma mark - View lifecycle
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- //创建静态库视图
- MyView *myView = [[MyView alloc] initWithFrame: CGRectMake(0, 0, 120, 100)];
- //将静态库视图添加至窗口当中
- [self.view addSubview:myView];
- [myView release];
- }
- - (void)viewDidUnload
- {
- [super viewDidUnload];
- // Release any retained subviews of the main view.
- // e.g. self.myOutlet = nil;
- }
- @end