actionSheet+Button(按钮)
来源:互联网 发布:php框架开发视频教程 编辑:程序博客网 时间:2024/06/05 18:35
用custometype方式创建按钮,不用背景图片,就可以设置按钮按下时的背景色。按下时按钮时背景是圆角的。要设置这个属性masktobounds为yes.
//// UCActionSheet.h// Zandouji//// Created by laizhenjie on 14-3-28.// Copyright (c) 2014年 Laizhenjie. All rights reserved.//#import <UIKit/UIKit.h>@interface UCActionSheet : UIView@property(nonatomic, strong) UIButton *favorButton;@property(nonatomic, strong) UIButton *cancelButton;@property(nonatomic, strong) UIButton *reportButton;@property(nonatomic, retain) UIView *bgViewForBts;@property(nonatomic, retain) UIView *bgColorAlpaView;- (void)show;@end
//// UCActionSheet.m// Zandouji//// Created by laizhenjie on 14-3-28.// Copyright (c) 2014年 Laizhenjie. All rights reserved.//#import "UCActionSheet.h"#import "UCColor+HexString.h"@interface UCActionSheet ()@end@implementation UCActionSheet@synthesize reportButton;@synthesize cancelButton;@synthesize favorButton;@synthesize bgViewForBts;@synthesize bgColorAlpaView;@synthesize amuseBean;@synthesize identifiId;//初始化函数- (id)initWithFrame:(CGRect)frame{ self = [super initWithFrame:frame]; if (self) { CGRect rect = [UIScreen mainScreen].bounds; self.frame = CGRectMake(0, 0, rect.size.width, rect.size.height); self.backgroundColor = [UIColor clearColor]; [self initBgViewWithFrame:rect]; } return self;}#define KBG_VIEW_WIDTH 320#define KBG_VIEW_HEIGHT 120- (void)initBgViewWithFrame:(CGRect)frame{ bgColorAlpaView = [[UIView alloc]initWithFrame:frame]; bgColorAlpaView.backgroundColor = [UIColor blackColor]; bgColorAlpaView.alpha = 0.5; [self addSubview:bgColorAlpaView]; bgViewForBts = [[UIView alloc]initWithFrame:CGRectMake( frame.size.width-KBG_VIEW_WIDTH, frame.size.height-KBG_VIEW_HEIGHT, KBG_VIEW_WIDTH, KBG_VIEW_WIDTH)]; [self addSubview:bgViewForBts]; [bgViewForBts setBackgroundColor:[UIColor clearColor]]; bgViewForBts.alpha = 1.0f; [self initWithSubviews:frame]; }#define KBUTTON_WHDTH 280#define KBUTTON_HEIGHT 44#define KVERTICAL_INTERVAL 5-(void)initWithSubviews:(CGRect)frame{ CGFloat dynamicY = 5.0f; favorButton = [[UIButton alloc]initWithFrame:CGRectMake(20.f, 5.0, KBUTTON_WHDTH, KBUTTON_HEIGHT)]; [favorButton addTarget:self action:@selector(clickedFavorBtn:) forControlEvents:UIControlEventTouchUpInside]; [favorButton setTitle:@"收藏" forState:UIControlStateNormal]; [favorButton setTitleColor:[UCColor_HexString colorWithHexString:@"#68c49d"] forState:UIControlStateNormal]; [favorButton setTag:1]; [self setButtonAppearence:favorButton]; [bgViewForBts addSubview:favorButton]; dynamicY = favorButton.frame.size.height +favorButton.frame.origin.y+5.0; reportButton = [[UIButton alloc]initWithFrame:CGRectMake(20.f, dynamicY, KBUTTON_WHDTH, KBUTTON_HEIGHT)]; [reportButton addTarget:self action:@selector(clickedReportBtn:) forControlEvents:UIControlEventTouchUpInside]; [reportButton setTag:2]; [reportButton setTitle:@"举报" forState:UIControlStateNormal]; [reportButton setTitleColor:[UCColor_HexString colorWithHexString:@"#d15050"] forState:UIControlStateNormal]; [self setButtonAppearence:reportButton]; [bgViewForBts addSubview:reportButton]; dynamicY = reportButton.frame.size.height +reportButton.frame.origin.y+5.0; cancelButton = [[UIButton alloc]initWithFrame:CGRectMake(20.f, dynamicY, KBUTTON_WHDTH, KBUTTON_HEIGHT)]; [cancelButton addTarget:self action:@selector(clickedCancelBtn:) forControlEvents:UIControlEventTouchUpInside]; [cancelButton setTag:3]; [cancelButton setTitle:@"取消" forState:UIControlStateNormal]; [cancelButton setTitleColor:[UCColor_HexString colorWithHexString:@"#666666"] forState:UIControlStateNormal]; [self setButtonAppearence:cancelButton]; [bgViewForBts addSubview:cancelButton]; bgViewForBts.frame = CGRectMake( frame.size.width-KBG_VIEW_WIDTH, frame.size.height-(KBUTTON_HEIGHT + KVERTICAL_INTERVAL)*3.0-KVERTICAL_INTERVAL*3.0, KBG_VIEW_WIDTH, (KBUTTON_HEIGHT + KVERTICAL_INTERVAL)* 3.0+KVERTICAL_INTERVAL*3.0); }#pragma mark -设置按钮的外观- (void)setButtonAppearence:(UIButton *)button{ button.layer.cornerRadius = 4.0f; button.layer.masksToBounds = YES; button.backgroundColor = [UCColor_HexString colorWithHexString:@"#ffffff"]; [button setBackgroundImage:[self buttonImageFromColor:[UCColor_HexString colorWithHexString:@"#dcdada"]] forState:UIControlStateHighlighted];// button.showsTouchWhenHighlighted = YES; //发光效果}//画一个view转成image- (UIImage *) buttonImageFromColor:(UIColor *)color { CGRect rect = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height); UIGraphicsBeginImageContext(rect.size); CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetFillColorWithColor(context, [color CGColor]); CGContextFillRect(context, rect); UIImage *img = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return img;}#pragma mark -- (void)show{ [[UIApplication sharedApplication].keyWindow.rootViewController.view addSubview:self]; [self addGestureSetting]; }- (IBAction)clickedFavorBtn:(UIButton *)sender{ NSLog(@"clickedFavorBtn."); [self removeFromSuperview]; }- (IBAction)clickedReportBtn:(UIButton *)sender{ [self removeFromSuperview];}- (IBAction)clickedCancelBtn:(UIButton *)sender{ [self removeFromSuperview];}#pragma mark - 添加单击、双击事件;-(void)addGestureSetting{ UITapGestureRecognizer *singleTapGestureInView = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(singleTapGestureInViewEvent:)]; singleTapGestureInView.numberOfTapsRequired = 1; //单击一下; [self addGestureRecognizer:singleTapGestureInView]; [singleTapGestureInView release]; }#pragma mark - 单击/双击事件函数;//单击事件关联函数:关闭当前的页面;-(IBAction)singleTapGestureInViewEvent:(UITapGestureRecognizer *)sender{ [self removeFromSuperview]; }#pragma mark 释放函数- (void)dealloc{ [super dealloc]; }@end
效果:
0 0
- actionSheet+Button(按钮)
- actionsheet按钮序号
- Button(按钮)监听
- 按钮(Button)
- 按钮组(Button group)
- MFC按钮控件(Button)
- Qt按钮控件(Button)
- CocosStudio(五)Button按钮
- Button 按钮
- Button按钮
- Button(按钮)
- 按钮 Button
- Button 按钮
- button按钮
- Button按钮
- Button按钮
- button按钮
- 按钮Button
- Linux硬盘分区和挂载
- Lvs的DR模式的配置详解
- Lvs的NAT模式的配置详解
- linux备份 还原数据库
- Lvs的tun模式的配置详解
- actionSheet+Button(按钮)
- lvs集群高可用性keepalived配置
- Zabbix 历史记录处出现问号乱码
- Lvs三种模式的思想及图解
- 只计算工作日2
- lvs相关yum源的配置和组件安装
- mapreduce远程调试
- mongodb分片集群搭建与测试
- Nginx的url重写