在表视图标题上添加投影

时间:2018-02-17 09:46:26

标签: ios swift uiview tableview

我的表格视图标题部分有以下标题

func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {


    let view = UIView()

    view.backgroundColor = .white



    // add a button
    let button = UIButton(type : .system)
    button.showsTouchWhenHighlighted = false
    button.frame = CGRect(x: 0 , y: 0 , width: 20 , height: 20 )

    if(collapsed[section])
    { button.backgroundColor = #colorLiteral(red: 0.8039215803, green: 0.8039215803, blue: 0.8039215803, alpha: 1)}
    else
    { button.backgroundColor = #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1)}

    button.addTarget(self, action: #selector(reloadTable), for: .touchUpInside)
    button.tag = section
    view.addSubview(button)
    button.bindFrameToSuperviewBounds()



    // add an Image
    let image = UIImageView(image: UIImage(named: "sup1"))
    image.frame = CGRect(x: 150 , y: 5 , width: 100 , height: 100)
    image.contentMode = .scaleAspectFit
    view.addSubview(image)


    // add a label
    let lblNew = UILabel()
    lblNew.frame = CGRect(x: 20, y: 100 , width: 100, height: 30)
    lblNew.text = "١٢٣ ر.س"
    lblNew.textColor = UIColor.myDarkGreen
    lblNew.translatesAutoresizingMaskIntoConstraints = false
    view.addSubview(lblNew)



   // view.dropShadow()

    return view

}

现在我想在节标题上添加阴影效果,看起来像这样

The desire output

我在这里尝试了一些解决方案,但它适用于不用作viewForHeaderInSection的简单视图,任何提示?

1 个答案:

答案 0 :(得分:2)

使用view的{​​{1}}的影子属性:

layer

结果:

What dependencies does running "git svn" need to have installed in order to run correctly?