使用 Swift 进行卡片视图 [英] Do card view with Swift

查看:54
本文介绍了使用 Swift 进行卡片视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能像帖子上的图片那样制作 UITableView ?
我想复制这个 Flat Effect,在项目之间有空格.>

想要的结果:

我有什么:

解决方案

你可以使用这个 cardview,告诉我它是否对你有用,对我有用.

https://github.com/aclissold/CardView/blob/master/README.md

<代码>////麻省理工学院许可证 (MIT)////版权所有 (c) 2014 Andrew Clissold////特此向任何获得副本的人免费授予许可//此软件和相关文档文件(软件")的处理//在软件中不受限制,包括但不限于权利//使用、复制、修改、合并、发布、分发、再许可和/或出售//软件的副本,并允许软件所属的人//提供这样做,受以下条件的约束:////以上版权声明和本许可声明应包含在所有//软件的副本或重要部分.////软件按原样"提供,不提供任何形式的明示或保证//暗示,包括但不限于适销性保证,//适合特定目的且不侵权.在任何情况下都不得//作者或版权持有人应对任何索赔、损害或其他责任//责任,无论是合同诉讼、侵权行为还是其他原因,均来自于,//与本软件或本软件的使用或其他交易无关或与之相关//     软件.//导入 UIKit@IBDesignable类 CardView: UIView {@IBInspectable var cornerRadius: CGFloat = 2@IBInspectable var shadowOffsetWidth: Int = 0@IBInspectable var shadowOffsetHeight: Int = 3@IBInspectable var shadowColor:UIColor?= UIColor.blackColor()@IBInspectable var shadowOpacity: Float = 0.5覆盖 func layoutSubviews() {layer.cornerRadius = 角半径让 shadowPath = UIBezierPath(roundedRect: bounds,cornerRadius:cornerRadius)layer.masksToBounds = falselayer.shadowColor = shadowColor?.CGColorlayer.shadowOffset = CGSize(width: shadowOffsetWidth, height: shadowOffsetHeight);layer.shadowOpacity = shadowOpacitylayer.shadowPath = shadowPath.CGPath}}

How can i make a UITableView like the picture on the post ?
I want to replicate this Flat Effect, with spaces between the items.

Result wanted :

Wath i have :

解决方案

You can use this cardview, tell me if it worked for you, it worked for me.

https://github.com/aclissold/CardView/blob/master/README.md

//
//  The MIT License (MIT)
//
//  Copyright (c) 2014 Andrew Clissold
//
//  Permission is hereby granted, free of charge, to any person obtaining a copy
//  of this software and associated documentation files (the "Software"), to deal
//  in the Software without restriction, including without limitation the rights
//  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//  copies of the Software, and to permit persons to whom the Software is
//  furnished to do so, subject to the following conditions:
//
//      The above copyright notice and this permission notice shall be included in all
//      copies or substantial portions of the Software.
//
//      THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//      IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//      FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//      AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//      LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//      OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
//      SOFTWARE.
//

import UIKit

@IBDesignable
class CardView: UIView {

    @IBInspectable var cornerRadius: CGFloat = 2

    @IBInspectable var shadowOffsetWidth: Int = 0
    @IBInspectable var shadowOffsetHeight: Int = 3
    @IBInspectable var shadowColor: UIColor? = UIColor.blackColor()
    @IBInspectable var shadowOpacity: Float = 0.5

    override func layoutSubviews() {
        layer.cornerRadius = cornerRadius
        let shadowPath = UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius)

        layer.masksToBounds = false
        layer.shadowColor = shadowColor?.CGColor
        layer.shadowOffset = CGSize(width: shadowOffsetWidth, height: shadowOffsetHeight);
        layer.shadowOpacity = shadowOpacity
        layer.shadowPath = shadowPath.CGPath
    }

}

这篇关于使用 Swift 进行卡片视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆