您的位置:首页 > 移动开发 > IOS开发

IOS开发知识点总结(一)

2014-09-29 19:59 369 查看


退回输入键盘

- (BOOL)textFieldShouldReturn:(id)textField{

[textField resignFirstResponder];

}

CGRect

CGRect frame = CGRectMake (origin.x,origin.y, size.width, size.height);矩形

NSStringFromCGRect(someCG) 把CGRect结构转变为格式化字符串;

CGRectFromString(aString) 由字符串恢复出矩形;

CGRectInset(aRect) 创建较小或较大的矩形(中心点相同),+较小 -较大

CGRectIntersectsRect(rect1, rect2) 判断两矩形是否交叉,是否重叠

CGRectZero 高度和宽度为零的/位于(0,0)的矩形常量

CGPoint & CGSize

CGPoint aPoint = CGPointMake(x, y);

CGSize aSize = CGSizeMake(width, height);

设置透明度

[myView setAlpha:value]; (0.0 < value < 1.0)

设置背景色

[myView setBackgroundColor:[UIColorredColor]];

(blackColor;darkGrayColor;lightGrayColor;

whiteColor;grayColor;redColor; greenColor;

blueColor;cyanColor;yellowColor;

magentaColor;orangeColor;purpleColor;

brownColor; clearColor;)

自定义颜色

UIColor *newColor = [[UIColor alloc]

initWithRed:(float) green:(float) blue:(float)alpha:(float)];

0.0~1.0

竖屏

320X480

横屏

480X320

状态栏高(显示时间和网络状态)

20 像素

导航栏、工具栏高(返回)

44像素

隐藏状态栏

[[UIApplication shareApplication]setStatusBarHidden: YES animated:NO]

横屏

[[UIApplication shareApplication]

setStatusBarOrientation:UIInterfaceOrientationLandscapeRight].

屏幕变动检测

orientation ==UIInterfaceOrientationLandscapeLeft

全屏

window=[[UIWindow alloc] initWithFrame:[UIScreenmainScreen] bounds];

自动适应父视图大小:

aView.autoresizingSubviews = YES;

aView.autoresizingMask =(UIViewAutoresizingFlexibleWidth |

UIViewAutoresizingFlexibleHeight);

定义按钮

UIButton *scaleUpButton = [UIButtonbuttonWithType:UIButtonTypeRoundedRect];

[scaleUpButton setTitle:@"放 大" forState:UIControlStateNormal];

scaleUpButton.frame = CGRectMake(40, 420,100, 40);

[scaleUpButton addTarget:self

action:@selector(scaleUp)

forControlEvents:UIControlEventTouchUpInside];

设置视图背景图片

UIImageView *aView;

[aView setImage:[UIImageimageNamed:@”name.png”]];

view1.backgroundColor = [UIColorcolorWithPatternImage:

[UIImageimageNamed:@"image1.png"]];

自定义UISlider的样式和滑块

[align=left][/align]
我们使用的是UISlider的setMinimumTrackImage,和setMaximumTrackImage方法来定义图片的,这两个方法可以设置滑块左边和右边的图片的,不过如果用的是同一张图片且宽度和控件宽度基本一致,就不会有变形拉伸的后果,先看代码,写在 viewDidLoad中:

[align=left] //左右轨的图片[/align]
[align=left] UIImage *stetchLeftTrack= [UIImageimageNamed:@"brightness_bar.png"];[/align]
[align=left] UIImage *stetchRightTrack = [UIImageimageNamed:@"brightness_bar.png"];[/align]
[align=left] //滑块图片[/align]
[align=left] UIImage *thumbImage = [UIImage imageNamed:@"mark.png"];[/align]
[align=left][/align]
[align=left] UISlider *sliderA=[[UISlider alloc]initWithFrame:CGRectMake(30, 320,257, 7)];[/align]
[align=left] sliderA.backgroundColor = [UIColor clearColor];[/align]
[align=left] sliderA.value=1.0;[/align]
[align=left] sliderA.minimumValue=0.7;[/align]
[align=left] sliderA.maximumValue=1.0;[/align]
[align=left][/align]
[align=left] [sliderA setMinimumTrackImage:stetchLeftTrackforState:UIControlStateNormal];[/align]
[align=left] [sliderA setMaximumTrackImage:stetchRightTrackforState:UIControlStateNormal];[/align]
[align=left] //注意这里要加UIControlStateHightlighted的状态,否则当拖动滑块时滑块将变成原生的控件[/align]
[align=left] [sliderA setThumbImage:thumbImage forState:UIControlStateHighlighted];[/align]
[align=left] [sliderA setThumbImage:thumbImage forState:UIControlStateNormal];[/align]
[align=left] //滑块拖动时的事件[/align]
[align=left] [sliderA addTarget:self action:@selector(sliderValueChanged:)forControlEvents:UIControlEventValueChanged];[/align]
[align=left] //滑动拖动后的事件[/align]
[align=left] [sliderA addTarget:self action:@selector(sliderDragUp:)forControlEvents:UIControlEventTouchUpInside];[/align]
[align=left][/align]
[align=left] [self.view addSubview:sliderA];[/align]
[align=left][/align]
[align=left]为了大家实验方便,我附上背景图brightness_bar.png和滑块图mark.png[/align]
[align=left]http://pic002.cnblogs.com/images/2011/162291/2011121611431816.png[/align]
[align=left]http://pic002.cnblogs.com/images/2011/162291/2011121611432897.png[/align]
[align=left][/align]
-(IBAction)sliderValueChanged:(id)sender{

UISlider *slider = (UISlider *) sender;

NSString *newText = [[NSString alloc]initWithFormat:@”%d”, (int)(slider.value + 0.5f)];

label.text = newText;

}

活动表单

<UIActi*****heetDelegate>

- (IBActive) someButtonPressed:(id)sender

{

UIActi*****heet *acti*****heet =[[UIActi*****heet alloc]

initWithTitle:@”Are you sure?”

delegate:self

cancelButtonTitle:@”No way!”

destructiveButtonTitle:@”Yes, I’m Sure!”

otherButtonTitles:nil];

[acti*****heetshowInView:self.view];

[acti*****heet release];

}

警告视图

<UIAlertViewDelegate>

- (void) acti*****heet:(UIActi*****heet *)acti*****heetdidDismissWithButtonIndex:(NSInteger) buttonIndex

{

if(buttonIndex !=[acti*****heet cancelButtonIndex])

{

NSString*message = [[NSString alloc] initWithFormat:@”You can

breathe easy, everything went OK.”];

UIAlertView *alert = [[UIAlertView alloc]

initWithTitle:@”Something was done”

message:message

delegate:self

cancelButtonTitle:@”OK”

otherButtonTitles:nil];

[alertshow];

[alertrelease];

[messagerelease];

}

}

动画效果

-(void)doChange:(id)sender

{

if(view2 == nil)

{

[self loadSec];

}

[UIView beginAnimati*****:nil context:NULL];

[UIView setAnimationDuration:1];

[UIView setAnimationTransition:([view1superview]?UIViewAnimationTransitionFlipFromLeft:UIViewAnimationTransitionFlipFromRight)forView:self.viewcache:YES];

if([view1 superview]!= nil)

{

[view1 removeFromSuperview];

[self.view addSubview:view2];

}else {

[view2 removeFromSuperview];

[self.view addSubview:view1];

}

[UIView commitAnimati*****];

}

Table View <UITableViewDateSource>

#pragma mark -

#pragma mark Table View Data Source Methods

//指定分区中的行数,默认为1

- (NSInteger)tableView:(UITableView*)tableView

numberOfRowsInSection:(NSInteger)section

{

return [self.listData count];

}

//设置每一行cell显示的内容

- (UITableViewCell *)tableView:(UITableView*)tableView

cellForRowAtIndexPath:(NSIndexPath*)indexPath

{

static NSString *SimpleTableIndentifier =@"SimpleTableIndentifier";

UITableViewCell *cell = [tableViewdequeueReusableCellWithIdentifier:SimpleTableIndentifier];

if (cell == nil) {

cell = [[[UITableViewCell alloc]

initWithStyle:UITableViewCellStyleSubtitle

reuseIdentifier:SimpleTableIndentifier]

autorelease];

}

UIImage *image =[UIImage imageNamed:@"13.gif"];

cell.imageView.image = image;

NSUInteger row = [indexPath row];

cell.textLabel.text = [listDataobjectAtIndex:row];

cell.textLabel.font =[UIFont boldSystemFontOfSize:20];

if(row < 5)

cell.detailTextLabel.text = @"Bestfriends";

else

cell.detailTextLabel.text =@"friends";

return cell;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: