IOS click to switch the background image

Source: Internet
Author: User

@ Property (nonatomic, strong) UIButton * weiXinButton;
@ Property (nonatomic, strong) UIButton * phoneButton;
@ Property (nonatomic, assign) BOOL isClick;

{
[Super viewDidLoad];
// Self. view. backgroundColor = [UIColor redColor];
_ LandButton = [UIButton buttonWithType: UIButtonTypeCustom];
_ LandButton. frame = CGRectMake (150,100, 60, 60 );
[_ LandButton setBackgroundImage: [UIImage imageNamed: @ "after.jpg"] forState: UIControlStateNormal];
_ LandButton. tag= 110;
[_ LandButton addTarget: self action: @ selector (aa :) forControlEvents: UIControlEventTouchUpInside];
[Self. view addSubview: _ landButton];

_ WeiXinButton = [UIButton buttonWithType: UIButtonTypeCustom];
_ WeiXinButton. frame = CGRectMake (150,200, 60, 60 );
[_ WeiXinButton setBackgroundImage: [UIImage imageNamed: @ "before.jpg"] forState: UIControlStateNormal];
[_ WeiXinButton addTarget: self action: @ selector (aa :) forControlEvents: UIControlEventTouchUpInside];
_ WeiXinButton. tag = 111;
[Self. view addSubview: _ weiXinButton];

_ PhoneButton = [UIButton buttonWithType: UIButtonTypeCustom];
_ PhoneButton. frame = CGRectMake (150,300, 60, 60 );
[_ PhoneButton setBackgroundImage: [UIImage imageNamed: @ "before.jpg"] forState: UIControlStateNormal];
[_ PhoneButton addTarget: self action: @ selector (aa :) forControlEvents: UIControlEventTouchUpInside];
_ PhoneButton. tag= 112;
[Self. view addSubview: _ phoneButton];
}

_ IsClick = YES;

Switch (sender. tag ){
Case 110:
{
[_ LandButton setBackgroundImage: [UIImage imageNamed: @ "after.jpg"] forState: UIControlStateNormal];
[_ WeiXinButton setBackgroundImage: [UIImage imageNamed: @ "beafore.jpg"] forState: UIControlStateNormal];
[_ PhoneButton setBackgroundImage: [UIImage imageNamed: @ "before.jpg"] forState: UIControlStateNormal];


}
Break;
Case 111:
{
_ IsClick = YES;
[_ WeiXinButton setBackgroundImage: [UIImage imageNamed: @ "after.jpg"] forState: UIControlStateNormal];
[_ LandButton setBackgroundImage: [UIImage imageNamed: @ "before.jpg"] forState: UIControlStateNormal];
[_ PhoneButton setBackgroundImage: [UIImage imageNamed: @ "before.jpg"] forState: UIControlStateNormal];


}
Break;
Case 112:
{
_ IsClick = YES;
[_ PhoneButton setBackgroundImage: [UIImage imageNamed: @ "after.jpg"] forState: UIControlStateNormal];
[_ LandButton setBackgroundImage: [UIImage imageNamed: @ "before.jpg"] forState: UIControlStateNormal];
[_ WeiXinButton setBackgroundImage: [UIImage imageNamed: @ "before.jpg"] forState: UIControlStateNormal];
}
Break;

Default:
Break;
}


}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.