簡體   English   中英

在表格視圖標題上添加陰影

[英]add drop shadow on a table view header

我的表視圖標頭部分有以下標頭

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

}

現在我想在部分標題上添加陰影效果,如下所示

欲望輸出

我在這里嘗試了一些解決方案,但是它可以在不用作viewForHeaderInSection的簡單視圖上工作,有什么提示嗎?

使用viewlayer的陰影屬性:

view.layer.shadowOpacity = 1
view.layer.shadowOffset = CGSize(width: 0, height: 1)
view.layer.shadowRadius = 1

結果:

截圖

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM