1.直接出来横屏用以下代码 - (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation != UIInterfaceOrientationPortrait); } 2.有重力感应直接用 - (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); } 方向右 UIInterfaceOrientationLandscapeLeft 方向左 UIInterfaceOrientationLandscapeRight 方向向上与方向向下 UIInterfaceOrientationPortraitUpsideDown 3.IPHONE虚拟机的位置 /Users/mac/Library/Application Support/iPhone Simulator/User/Applications/ 4.隐藏导航的方法 //隐藏导航 [super.navigationController setNavigationBarHidden:TRUE animated:TRUE]; //setNavigationBarHidden:TRUE/FALSE显示或隐藏 //只在当前VIEW隐藏 - (void)viewWillAppear:(BOOL)animated { [[self navigationController] setNavigationBarHidden:YES]; } 5.将TextField设置成密码 //密码 textField.secureTextEntry = YES; 6.UIImageView响应点击事件 方法一: - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [[event allTouches] anyObject]; if ([touch view] != UIImageView) { //do some method..... } } 方法二: subview.userInteractionEnabled = YES; UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)]; [subview addGestureRecognizer:singleTap]; [singleTap release]; - (void)handleSingleTap:(UIGestureRecognizer *)gestureRecognizer { //do something.... } 7.限制UITextField长度 在 iPhone 应用里经常要限制用户输入字符的长度,比如密码输入框规定密码长度是 x 到 y 位,下面这段代码可以让 UITextField 限制输入长度。 - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { if (range.location >= 12) return NO; // return NO to not change text return YES; } 现实: textField = [[UITextField alloc] initWithFrame:CGRectMake(100, 100, 200, 50)]; textField.backgroundColor = [UIColor redColor]; textField.delegate = self; [self.view addSubview:textField];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
}
如果这段代码不起作用的话, 那么一定要注意一个问题, 在Targeted Device Family的值改为iPhone/iPad . 这样这段代码才起作用!
如果父视图为ParentView包含一个Button, 如果再ParentView上添加子视图ChildView, 且ChildView盖住了Button,那么 Button就得到不响应了, 为了让Button响应, 可以设置ChildView的userInteractionEnabled = NO;
clipsToBounds属性
取值:BOOL(YES/NO)
作用:决定了子视图的显示范围。具体的说,就是当取值为YES时,剪裁超出父视图范围的子视图部分;当取值为NO时,不剪裁子视图。默认值为NO。
预留
预留
预留
预留
预留
预留
预留
预留
预留