• 纯代码实现实现各种效果的圆角按钮。


    #import <UIKit/UIKit.h>
    
    @interface APRoundedButton : UIButton
    
    @property (nonatomic, assign) int style;
    
    @end
    //
    //  Created by Alberto Pasca on 27/02/14.
    //  Copyright (c) 2014 albertopasca.it. All rights reserved.
    //
    
    #import "APRoundedButton.h"
    #import <QuartzCore/QuartzCore.h>
    
    
    @implementation APRoundedButton
    
    - (void)awakeFromNib
    {
      [super awakeFromNib];
    
      UIRectCorner corners;
    
    
      switch ( self.style )
      {
        case 0:
          corners = UIRectCornerBottomLeft;
          break;
        case 1:
          corners = UIRectCornerBottomRight;
          break;
        case 2:
          corners = UIRectCornerTopLeft;
          break;
        case 3:
          corners = UIRectCornerTopRight;
          break;
        case 4:
          corners = UIRectCornerBottomLeft | UIRectCornerBottomRight;
          break;
        case 5:
          corners = UIRectCornerTopLeft | UIRectCornerTopRight;
          break;
        case 6:
          corners = UIRectCornerBottomLeft | UIRectCornerTopLeft;
          break;
        case 7:
          corners = UIRectCornerBottomRight | UIRectCornerTopRight;
          break;
        case 8:
          corners = UIRectCornerBottomRight | UIRectCornerTopRight | UIRectCornerTopLeft;
          break;
        case 9:
          corners = UIRectCornerBottomRight | UIRectCornerTopRight | UIRectCornerBottomLeft;
          break;
        default:
          corners = UIRectCornerAllCorners;
          break;
      }
    
    
      UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds
                                                     byRoundingCorners:corners
                                                           cornerRadii:CGSizeMake(20.0, 30.0)];
      CAShapeLayer *maskLayer = [CAShapeLayer layer];
      maskLayer.frame         = self.bounds;
      maskLayer.path          = maskPath.CGPath;
      self.layer.mask         = maskLayer;
    }
    
    
    @end
  • 相关阅读:
    C# 多线程Thread.IsBackground=True的作用
    JS 判断用户设备 移动端或桌面端
    VSCode 代码格式化 快捷键
    PHP 根据 IP 获取定位数据
    C# 将文本写入到文件
    C# 读取文件内容
    PHP 美化输出数组
    VSCode 设置 Tab 空格
    custom post types 404 Page Error
    [已解决] wordpress 修改 permalink 后 页面 404 问题
  • 原文地址:https://www.cnblogs.com/yunis/p/3909521.html
Copyright © 2020-2023  润新知