UIButton设置背景图片(经过渲染的图片)与不渲染的区别

//UIButton :创建UIButton

    //自己格式

    UIButton *tapButton = [UIButton buttonWithType:UIButtonTypeSystem];

    

    tapButton.frame = CGRectMake(50, 150, 150, 30);

    //tapButton.backgroundColor = [UIColor cyanColor];

    [self.view addSubview:tapButton];

//设置button前景图片(按钮一般都是view)

    

     UIImage *buttonimage = [UIImage imageNamed:@"button.png"];

     //[tapButton setImage:buttonimage forState:(UIControlStateNormal)];

    

    //设置图像渲染方式

    buttonimage = [buttonimage imageWithRenderingMode:(UIImageRenderingModeAlwaysOriginal)];

    [tapButton setImage:buttonimage forState:(UIControlStateNormal)];

    

    

    //button添加向应方法

    //target:目标,button被点击时 ,要执行操作的对象

    //action:行为 方法.button被点击时 目标对象要执行的操作.

    //events:事件,触摸button的方式.

    [tapButton addTarget:self action:@selector(returnKeyboard:) forControlEvents:(UIControlEventTouchUpInside)];

图片经过渲染的显示为:

UIButton设置背景图片(经过渲染的图片)与不渲染的区别_第1张图片



如果图片不经过渲染为:

  //UIButton :创建UIButton

    //自己格式

    UIButton *tapButton = [UIButton buttonWithType:UIButtonTypeSystem];

    

    tapButton.frame = CGRectMake(50, 150, 150, 30);

    //tapButton.backgroundColor = [UIColor cyanColor];

    [self.window addSubview:tapButton];

    [tapButton setImage:[UIImage imageNamed:@"button.png"] forState:(UIControlStateNormal)];

    

    [tapButton addTarget:self action:@selector(returnKeyboard:) forControlEvents:(UIControlEventTouchUpInside)];

    


UIButton设置背景图片(经过渲染的图片)与不渲染的区别_第2张图片

你可能感兴趣的:(iOS)