摘要:@interface RootViewController : UIViewController{ UIView *view;}-(void)createBackgroundView{ view = [[UIView alloc]initWithFrame:self.view.frame]; view.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.0]; view.opaque = NO;UIWindow *appWindow = [[UIApplicationsha...
阅读全文
摘要:#import "AsyncImageView.h"@implementation AsyncImageView - (id)initWithFrame:(CGRect)frame{ self = [super initWithFrame:frame]; if (self) { // Initialization code } return self;} - (void)loadImageFromURL:(NSURL*)url { if (connection!=nil) { [connection release]; } if (data!...
阅读全文
摘要:在ios6之前我们旋转屏幕只需要实现shouldAutorotateToInterfaceOrientation就行了- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{ return YES;}但是ios6上这个就失效了,需要实现shouldAutorotate 和 supportedInterfaceOrientations具体步骤是1. Delegate里面要分开判断ios版本,setRootViewController方法是不同的:1 if ( [[...
阅读全文
摘要:1.更改UINavigationController push 到另一个界面返回按钮的titleself.navigationController.navigationBar.topItem.backBarButtonItem = [[UIBarButtonItem alloc]initWithTi...
阅读全文
摘要:1 // 2 // ViewController.m 3 // testGestures 4 // 5 // Created by shawn li on 13-7-29. 6 // Copyright (c) 2013年 bigbellshawn. All rights reserved. 7 // 8 9 #import "ViewController.h" 10 11 @interface ViewController () 12 @property (nonatomic, strong) UIImageView *imageView; 13 @end 1...
阅读全文
摘要:摘要:CoreGraphics的功能非常强大,可以绘制各种图形;今天学习一下怎么绘制简单的点线面,记录学习。一、导入coreGraphics.framework二、绘制图形1、绘制矩形// 绘制矩形- (void)drawRectangle { // 定义矩形的rect CGRect rectangle = CGRectMake(100, 290, 120, 25); // 获取当前图形,视图推入堆栈的图形,相当于你所要绘制图形的图纸 CGContextRef ctx = UIGraphicsGetCurrentContext(); // 在当前路...
阅读全文
摘要:1.画线条(实线,虚线)- (void)drawRect:(CGRect)rect{ CGContextRef context = UIGraphicsGetCurrentContext(); [self drawXLine:context rect:rect]; [self drawLegend:context rect:rect];}-(CGContextRef)drawXLine:(CGContextRef)context rect:(CGRect)rect{ CGContextSetStrokeColorWithColor(context, [UIColor redColo...
阅读全文
摘要:1. 内总管理原则(引用计数) IOS的对象都继承于NSObject, 该对象有一个方法:retainCount ,内存引用计数。 引用计数在很多技术都用到: window下的COM组件,多线程的信号量,读写锁,思想都一样。 (一般情况下: 后面会讨论例外情况) alloc 对象分配后引用计数为1 retain 对象的引用计数+1 copy copy 一个对象变成新的对象(新内存地址) 引用计数为1 原来对象计数不变 release 对象引用计数-1 如果为0释放内存 autorelease 对象引用计数-1 如果为0不马上释放,最近一个个pool时释...
阅读全文
摘要:为了进行页面传值,也可以用委托的方法。下面以时间控件为例。1.首先,在.h 文件设置委托#import @protocol DatePickerViewDelegate;@class DatePickerView;@interface DatePickerView :UIView@property (strong, nonatomic) NSString *dateContent;@property (strong, nonatomic) UIDatePicker *datePicker;@property (assign, nonatomic) id delegate;-(void...
阅读全文
摘要:1.首先在Interface Builder中选择TextFields,然后在Text Field Attributes中找到Text Input Traits,选择Return Key为done。2.定义方法- (IBAction) textFieldDoneEditing:(id)sender; //按下Done键关闭键盘//按完Done键以后关闭键盘- (IBAction) textFieldDoneEditing:(id)sender{ [sender resignFirstResponder];}3.然后找到事件Did En...
阅读全文
摘要:NSArray *nib = [[NSBundle mainBundle]loadNibNamed:[pages objectAtIndex:0] owner:self options:nil];//得到第一个UIViewUIView *tmpCustomView = [nib objectAtIndex:0];//获得屏幕的Frame//CGRect tmpFrame = [[UIScreen mainScreen] bounds];[self.view addSubView:tmpCustomView];
阅读全文
摘要:概述:造成unrecognized selector sent to instance iphone,大部分情况下是因为对象被提前release了,在你心里不希望他release的情况下,指针还在,对象已经不在了。很多时候,是因为init初始化函数中,对属性赋值没有使用self.foo赋值,而是直接对foo赋值,导致属性对象没有retain(心里以为retain了),而提前释放。造成unrecognized selector sent to instance XXX,大部分情况下是因为对象被提前release了,在你心里不希望他release的情况下,指针还在,对象已经不在了。问题解决链接:h
阅读全文
摘要:1.添加委托UITextFieldDelegate2.-(BOOL)textFieldShouldReturn:(UITextField *)textField { [textField resignFirstResponder]; return YES;} //隐藏键盘- (void...
阅读全文
摘要:原文网址:http://blog.csdn.net/m_changgong/article/details/8115137 作者:张燕广1、创建一个Single View Application工程,命名为:TableViewDemo,如下图2、修改ViewController.xib,添加一个Table View控件,连接操作,如下3、视图控制器ViewController,需要实现协议UITableViewDataSource、UITableViewDelegate中的必须实现的方法,在工程目录依次展开Frameworks->UIKit.framework->Headers,然
阅读全文
摘要:在iOS6中,如果像旧版本的资料提到的那样,用IB将一个ScrollView拖到.h文件中创建一个outlet,并在viewDidLoad函数中设置ScrollView的contentSize属性的话,会发现运行的程序中ScrollView可见,但无法拖动。这是因为iOS6中的AutoLayout机制,在viewDidLoad函数被执行后,AutoLayout会重新把contentSize修改为符合屏幕大小的数值(也就是说,现在的contentSize又适合了屏幕大小,并没有大于UIScrollView本身的大小,当然也就不能滚动了)。解决办法是重写viewDidAppear:(BOOL)an
阅读全文
摘要:.h文件中@interface ViewController:UIViewController{ IBOutlet UIImageView *imageView;}一、UIView 简单的动画效果(UIViewAnimation)1.向上翻页[UIView beginAnimations:@"animationID" context:nil];[UIView setAnimationDuration:8];[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];[UIWindow setAnimationsEnabled
阅读全文
摘要:(1)引入“QuartzCore.framework”库,头部引用。#include<QuartzCore/QuartzCore.h>(2)直接上代码,你懂的。-(IBAction)buttonP:(id)sender{ [self buttonAnimation:sender];}- (CAAnimation *) animationRotate { CATransform3D rotationTransform = CATransform3DMakeRotation( M_PI/2 , 0 , 1 , 0 ); CABasicAnimation* animation; ...
阅读全文
摘要:iOS设备现在有四种不同的分辨率:iPhone 320x480、iPhone4 640x960、iphone5 1136x640、iPad 768x1024。以前程序的启动画面(图片)只要准备一个 Default.png就可以了,但是现在变得复杂多了。下面就是CocoaChina 会员做得总结如果一个程序,既支持iPhone又支持iPad,那么它需要包含下面几个图片:Default-Portrait.png iPad专用竖向启动画面 768x1024或者768x1004Default-Landscape.png iPad专用横向启动画面 1024x768或者1024x748Default-Po
阅读全文