关于ios 读书笔记

 在ViewDidLoad中加入:

UIMenuItem *menuItem = [[UIMenuItem alloc]initWithTitle:@"分享到新浪微博" action:@selector(changeColor:)];

UIMenuController *menu = [UIMenuController sharedMenuController];

[menu setMenuItems:[NSArray arrayWithObject:menuItem]];

[menuItem release];

当然上面那个@selector里面的changeColor方法还是自己写吧,也就是说点击了我们自定义的菜单项后会触发的方法。

然后还得在代码里加上一个方法:

-(BOOL)canPerformAction:(SEL)action withSender:(id)sender

{

      if(action ==@selector(changeColor:))

      {

           if(textView.selectedRange.length>0)

               return YES;

      }

      return NO;

}



 这种方法,打完电话后还会回到原来的程序,也会弹出提示,推荐这种 
 NSMutableString * str=[[NSMutableString alloc] initWithFormat:@"tel:%@",@"186xxxx6979"];
    UIWebView * callWebview = [[UIWebView alloc] init];
    [callWebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]]];
    [self.view addSubview:callWebview];
    [callWebview release];
    [str release]; 


把图片倒过来
  UIImage *loadImage=[UIImage imageNamed:@"zan"];
    CGImageRef cgimage=loadImage.CGImage;


    loadImage = [UIImage imageWithCGImage:cgimage scale:1. orientation:UIImageOrientationDown];、


按照所选的区域大小截图
   //    UIGraphicsBeginImageContext(CGSizeMake(320, 200));
        //    [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
        //    UIImage*parentImage=UIGraphicsGetImageFromCurrentImageContext();
        //    CGImageRef imageRef = parentImage.CGImage;
        //    CGRect myImageRect=CGRectMake(0, 100, 320, 100);
        //    CGImageRef subImageRef = CGImageCreateWithImageInRect(imageRef, myImageRect);
        //    CGSize size=CGSizeMake(320, 100);
        //    UIGraphicsBeginImageContext(size);
        //    CGContextRef context = UIGraphicsGetCurrentContext();
        //    CGContextDrawImage(context, myImageRect, subImageRef);
        //    UIImage* image = [UIImage imageWithCGImage:subImageRef];
        //    UIGraphicsEndImageContext();
        //    CGImageRelease(imageRef);
        //    UIGraphicsEndImageContext();


uiview 转uiimage
 -(UIImage *)getImageFromView:(UIView *)theView
{
    //UIGraphicsBeginImageContext(theView.bounds.size);
    UIGraphicsBeginImageContextWithOptions(theView.bounds.size, YES, theView.layer.contentsScale);
    [theView.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *image=UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;


图片的缩放方法
 -(UIImage *)OriginImage:(UIImage *)image scaleToSize:(CGSize)size
{
    UIGraphicsBeginImageContext(size);  //size 为CGSize类型,即你所需要的图片尺寸

    [image drawInRect:CGRectMake(0, 0, size.width, size.height)];

    UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    return scaledImage;   //返回的就是已经改变的图片


你可能感兴趣的:(ios)