简体   繁体   中英

How to populate Custom UIView in swift 2?

I am new to swift and iOS development, and its quite confusing! I come from web development environment using php, mysql and html (a smarter environment ;) )

My goal here is to list data in cool design not typical table view, so I am using a custom class "CardView" that I found on the internet:

import UIKit

@IBDesignable
public 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 public 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
}

}

I added the CardView as framework, played around with it in storyboard. I made a card with my preferences of shadow and border-radius, now I want to get serious and render each data set in a card, and list all cards vertically.

在此处输入图片说明

I included the CardView class to my ViewController, now what? :) How to begin I am confused.. I know I need a class to take array of data, then loop through the array, and print each data inside a CardVeiw object.

I am just not sure how to make that! totally new mac user, and new to xcode.

Your next steps are:

  1. Change your UIView to a UITableViewCell

  2. Add everything necessary for a UITableViewCell Class

  3. Add a Tableview to your ViewController and load the CustomTableViewCells in this TableView

For everything above there are a lot tutorials out there. I hope this helps.

There are no limits. You won't get a normal tableview if you use your own CustomCells.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM