第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

iOS多邊形按鍵的創(chuàng)建

標(biāo)簽:
iOS

前几天项目需要,要做一个楼盘或者户型图的原生交互页面,
不清楚有没有更简单直白又高级的方法,我第一个想到的是创建一堆
多边形按钮。
所以我们就需要一个抽象的类,可以由贝赛尔曲线创建按键,是UIButton的子类

内容如下,如果大家有好的方案,请不吝赐教:

按键抽象类头文件

//
//  RLCShapeButton.h
//  duobianxing
//
//  Created by Realank on 16/2/16.
//  Copyright © 2016年 iMooc. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface RLCShapeButton : UIButton

- (instancetype)initWithPath:(UIBezierPath *)path andOrigin:(CGPoint)point;

@end

按键抽象类实现文件:

//
//  RLCShapeButton.m
//  duobianxing
//
//  Created by Realank on 16/2/16.
//  Copyright © 2016年 iMooc. All rights reserved.
//

#import "RLCShapeButton.h"

@interface RLCShapeButton ()

@property(nonatomic, strong) UIBezierPath *path;

@end
@implementation RLCShapeButton

- (instancetype)initWithPath:(UIBezierPath *)path andOrigin:(CGPoint)point{
    if (self = [super initWithFrame:CGRectMake(point.x, point.y, path.bounds.size.width, path.bounds.size.height)]) {
        _path = path;
        CAShapeLayer *shapLayer = [CAShapeLayer layer];
        shapLayer.path = self.path.CGPath;
        shapLayer.strokeColor = [UIColor redColor].CGColor;
        shapLayer.lineWidth = 5;
        shapLayer.fillColor = [UIColor clearColor].CGColor;
//        self.layer.mask = shapLayer;
        [self.layer addSublayer:shapLayer];
    }
    return self;
}

//覆盖方法,点击时判断点是否在path内,YES则响应,NO则不响应
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
{
    BOOL res = [super pointInside:point withEvent:event];
    if (res)
    {
        if ([self.path containsPoint:point])
        {
            return YES;
        }
        return NO;
    }
    return NO;
}

@end

在ViewController中创建并使用这个按键类:

- (void)viewDidLoad {
    [super viewDidLoad];

    UIBezierPath* path = [[UIBezierPath alloc]init];
    [path moveToPoint:CGPointMake(0, 0)];
    [path addLineToPoint:CGPointMake(50, 50)];
    [path addLineToPoint:CGPointMake(100, 50)];
    [path addLineToPoint:CGPointMake(100,100)];
    [path addLineToPoint:CGPointMake(0, 100)];
    [path closePath];

    RLCShapeButton *button = [[RLCShapeButton alloc]initWithPath:path andOrigin:CGPointMake(100, 100)];
    [button addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];

}

- (void)click {
    NSLog(@"click");
}

按键的大小,根据创建时提供的贝赛尔曲线大小,自动设置,是不是很方便呢~~

點(diǎn)擊查看更多內(nèi)容
10人點(diǎn)贊

若覺(jué)得本文不錯(cuò),就分享一下吧!

評(píng)論

作者其他優(yōu)質(zhì)文章

正在加載中
移動(dòng)開(kāi)發(fā)工程師
手記
粉絲
11
獲贊與收藏
446

關(guān)注作者,訂閱最新文章

閱讀免費(fèi)教程

感謝您的支持,我會(huì)繼續(xù)努力的~
掃碼打賞,你說(shuō)多少就多少
贊賞金額會(huì)直接到老師賬戶
支付方式
打開(kāi)微信掃一掃,即可進(jìn)行掃碼打賞哦
今天注冊(cè)有機(jī)會(huì)得

100積分直接送

付費(fèi)專欄免費(fèi)學(xué)

大額優(yōu)惠券免費(fèi)領(lǐng)

立即參與 放棄機(jī)會(huì)
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)

舉報(bào)

0/150
提交
取消