在我的项目中,我想像这样使用 SVGKImageView 和 UILabel 以编程方式设计自定义视图单元
这里 square 是一个 SVGKImageView & “Dadar” 是一个 UILabel。
但现在我得到这样的输出
这是我的代码
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell
{
// intialize collection cell with media collection cell
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("mediaCell", forIndexPath: indexPath) as! ViewContentMediaCollectionCell
// get the data from view model
let viewModelobj = mViewContentViewModelObj!.getViewContentData()
// set the page imageview frame with default size
var mSVGImageView = SVGKFastImageView(frame: CGRect(x: 0, y: 0, width: cell.frame.width, height: (50)))
// set the pageImageview with actual pageImage
mSVGImageView = SVGKFastImageView(SVGKImage: viewModelobj[indexPath.row].mContentPage)
// add page imageview in the cell
cell.contentView.addSubview(mSVGImageView)
// add the title label
let titleLabel : UILabel = UILabel(frame: CGRect(x: 0, y: cell.frame.height - 20, width: cell.frame.width, height: 20))
// set the page title
titleLabel.text = viewModelobj[indexPath.row].mPageTitle
// add title label to the collection view cell
cell.contentView.addSubview(titleLabel)
// return the cell
return cell
}