IPHONE开发笔记

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。
 

 

预留

预留

预留

 

预留

预留

预留

预留

预留

预留

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值