给button增加点击事件时这个地方也加上了 UIControlEventTouchUpOutside 这个

本文详细介绍了如何在iOS应用中自定义按钮的样式、颜色、文本对齐方式,并配置了触摸事件响应机制,包括点击按钮时的颜色变化及按钮外点击事件的处理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

self.typeButton = [UIButtonbuttonWithType:UIButtonTypeCustom];

        self.typeButton.frame =self.bounds;

        self.typeButton.showsTouchWhenHighlighted =YES;

        self.typeButton.titleLabel.textAlignment =GNTextAlignmentCenter;

        UIColor* color = [UIColorcolorWithRed:136.f/255.fgreen:90.f/255.fblue:31.f/255.falpha:1.0f];

        [self.typeButtonsetTitleColor:color forState:UIControlStateNormal];

        self.typeButton.titleLabel.font = [UIFontsystemFontOfSize:10.0f];

        self.typeButton.titleLabel.textAlignment =GNTextAlignmentCenter;

        [self.typeButtonsetTitleEdgeInsets:UIEdgeInsetsMake(25.0f, -19.0f,10.0f,0.0f)];

        [self.typeButtonsetImageEdgeInsets:UIEdgeInsetsMake(4.0f,12.0f, 20.0f,12.0f)];

        [self.typeButtonaddTarget:self action:@selector(handleLandTipSelected:)

                  forControlEvents:UIControlEventTouchUpInside|UIControlEventTouchUpOutside];

        [self addSubview:self.typeButton];


PS:查了下资料,UIControlEventTouchUpOutside 这个貌似是点击button后不放开,然后拖动到外面,接着才放开的事件

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值