zoukankan      html  css  js  c++  java
  • iOS小技巧

    键盘透明:  
    
    textField.keyboardAppearance = UIKeyboardAppearanceAlert;
    状态栏的网络活动风火轮是否旋转:
    
    [UIApplication sharedApplication].networkActivityIndicatorVisible , 默认值是 NO 。 
    .截取屏幕图片:
    
    // 创建一个基于位 图的图形上下文并指定大小为CGSizeMake(200,400) 
    UIGraphicsBeginImageContext(CGSizeMake(200,400));  
     
    //renderInContext  呈现接受者及其子范围到 指定的上下文 
    [self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; 
        // 返回 一个基于当前图形上下文的图片 
     UIImage *aImage = UIGraphicsGetImageFromCurrentImageContext(); 
      // 移除栈顶 的基于当前位图的图形上下文 
    UIGraphicsEndImageContext(); 
    // 以 png 格式 返回指定图片的数据 
    imageData = UIImagePNGR epresentation(aImage); 
    更改cell选中的背景: 
    
    UIView *myview = [[UIView alloc] init]; 
       myview.frame = CGRectMake(0, 0, 320, 47); 
       myview.backgroundColor = [UIColorcolorWithPatternImage:[UIImage imageNamed:@"0006.png"]]; 
       cell.selectedBackgroundView = myview;
    .显示图片:
    
    CGRect myImageRect = CGRectMake(0.0f, 0.0f, 320.0f, 109.0f);  
    UIImageView *myImage = [[UIImageView alloc] initWithFrame:myImageRect]; 
    [myImage setImage:[UIImage imageNamed:@"myImage.png"]];  
    myImage.opaque = YES; //opaque 是否透明 
    [self.view addSubview:myImage];
    能让图片适应框的大小(beta)
     
    NSString*imagePath = [[NSBundle mainBundle] pathForResource:@"XcodeCrash"ofType:@"png"];      
        UIImage *image = [[UIImage alloc]initWithContentsOfFile:imagePath];  
            UIImage *newImage= [image transformWidth:80.f height:240.f];  
        UIImageView *imageView = [[UIImageView alloc]initWithImage: newImage];  
             [newImagerelease];  
        [image release];  
        [self.view addSubview:imageView];
      实现点击图片进行跳转的代码:(生成一个带有背景图片的button,给button绑定想要的事件)
    
    UIButton *imgButton=[[UIButton alloc]initWithFrame:CGRectMake(0, 0, 120, 120)];  
    [imgButton setBackgroundImage:(UIImage *)[self.imgArray objectAtIndex:indexPath.row] forState:UIControlStateNormal];  
    imgButton.tag=[indexPath row];  
    [imgButton addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];  
    .第二种方法:在背景图片上添加Tap事件,相应单击处理。这种方法,很好代替了button方式,但是如果UI上没有背景图片,这种方法又回到到第一种山寨的方法行列中。
    
    // 添加带有处理时间的背景图片 
    
    UIImageView *backView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];  
     
        backView.image = [UIImage imageNamed:@"small3.png"];  
     
          
     
        backView.userInteractionEnabled = YES;  
     
        UITapGestureRecognizer *singleTouch = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissKeyboard:)];  
     
        [backView addGestureRecognizer:singleTouch];  
     
          
     
        backView.tag = 110;  
     
        [self.view addSubview:backView];  
     
     
     
    -(void)dismissKeyboard:(id)sender{  
     
        [text resignFirstResponder];  
     
    }  
  • 相关阅读:
    MVC三层架构学习总结实例
    JSON & Ajax
    设计模式之单例模式
    设计模式之静态工厂方法
    Gitee 添加了ssh公钥还是需要账户和密码
    MySQL日期时间函数大全[转]
    session 注意事项
    session 入库2 垃圾回收机制
    session 入库的实现
    PHP实现手机号码中间四位用星号(*)隐藏的自定义函数分享
  • 原文地址:https://www.cnblogs.com/Ganggang888/p/5253563.html
Copyright © 2011-2022 走看看