退回输入键盘:
- - (BOOL) textFieldShouldReturn:(id)textField{
- [textField resignFirstResponder];
- }
CGRect
CGPoint & CGSize
- CGPoint aPoint = CGPointMake(x, y); CGSize aSize = CGSizeMake(width, height);
设置透明度
- [myView setAlpha:value]; (0.0 < value < 1.0)
设置背风景
- [myView setBackgroundColor:[UIColor redColor]];
- (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
宽度和高度
1
|
768X1024 1024X768 状态栏高 20 像素高 导航栏 工具栏 44像素高
|
隐藏状态栏:
- [[UIApplication shareApplication] setStatusBarHidden: YES animated:NO]
横屏:
- [[UIApplication shareApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight].
- orientation == UIInterfaceOrientationLandscapeLeft
- window=[[UIWindow alloc] initWithFrame:[UIScreen mainScreen] bounds];全屏
自动适应父视图大小:
- aView.autoresizingSubviews = YES;
- aView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
定义按钮
- UIButton *scaleUpButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
- [scaleUpButton setTitle:@"放 大"forState:UIControlStateNormal];
- scaleUpButton.frame = CGRectMake(40, 420, 100, 40);
- [scaleUpButton addTarget:self action:@selector(scaleUp) forControlEvents:UIControlEventTouchUpInside];
设置视图背景图片
- UIImageView *aView;
- [aView setImage:[UIImage imageNamed:@”name.png”]];
- view1.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"image1.png"]];
- UISlider *slider = (UISlider *) sender;
- NSString *newText = [[NSString alloc] initWithFormat:@”%d”, (int)(slider.value + 0.5f)];
- label.text = newText;
活动表单 <UIActionSheetDelegate>
- - (IBActive) someButtonPressed:(id) sender
- {
- UIActionSheet *actionSheet = [[UIActionSheet alloc]
- initWithTitle:@”Are you sure?”
- delegate:self
- cancelButtonTitle:@”No way!”
- destructiveButtonTitle:@”Yes, I’m Sure!”
- otherButtonTitles:nil];
- [actionSheet showInView:self.view];
- [actionSheet release];
- }
正告视图 <UIAlertViewDelegate>
- - (void) actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger) buttonIndex
- {
- if(buttonIndex != [actionSheet 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];
- [alert show];
- [alert release];
- [message release];
- }
- }
动画效果
- -(void)doChange:(id)sender
- {
- if(view2 == nil)
- {
- [self loadSec];
- }
- [UIView beginAnimations:nil context:NULL];
- [UIView setAnimationDuration:1];
- [UIView setAnimationTransition:([view1 superview] ? UIViewAnimationTransitionFlipFromLeft : UIViewAnimationTransitionFlipFromRight)forView : self.view cache:YES];
- if([view1 superview]!= nil)
- {
- [view1 removeFromSuperview];
- [self.view addSubview:view2];
- }else{
- [view2 removeFromSuperview];
- [self.view addSubview:view1];
- }
- [UIView commitAnimations];
- }
Table View <UITableViewDateSource>
- #pragma mark -
- #pragma mark Table View Data Source Methods
- //指定分区中的行数,默许为1
- - (NSInteger)tableView:(UITableView *)tableView
- numberOfRowsInSection:(NSInteger)section
- {
- return[self.listDatacount];
- }
- //设置每行cell显示的内容
- - (UITableViewCell *)tableView:(UITableView *)tableView
- cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- staticNSString *SimpleTableIndentifier = @"SimpleTableIndentifier";
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: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 = [listData objectAtIndex:row];
- cell.textLabel.font = [UIFont boldSystemFontOfSize:20];
- if(row < 5)
- cell.detailTextLabel.text = @"Best friends";
- else
- cell.detailTextLabel.text = @"friends";
- returncell;
- }
图象:如果设置图象,则它显示在文本的左边
文本标签:这是单元的主要文本(UITableViewCellStyleDefault 只显示文本标签)
详细文本标签:这是单元的辅助文本,通经常使用作解释性说明或标签
- UITableViewCellStyleSubtitle
- UITableViewCellStyleDefault
- UITableViewCellStyleValue1
- UITableViewCellStyleValue2
- <UITableViewDelegate>
- #pragma mark -
- #pragma mark Table View Delegate Methods
- //把每行缩升级别设置为其行号
- - (NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- NSUInteger row = [indexPath row];
- returnrow;
- }
- //获得传递过来的indexPath值
- - (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
- NSUInteger row = [indexPath row];
- if(row == 0)
- returnnil;
- returnindexPath;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
------分隔线----------------------------
------分隔线----------------------------