gpt4 book ai didi

ios - 在 TableView 标题上添加阴影

转载 作者:行者123 更新时间:2023-11-28 10:44:57 24 4
gpt4 key购买 nike

我的 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 的简单 View ,有什么提示吗?

最佳答案

使用viewlayer的阴影属性:

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

结果:

screenshot

关于ios - 在 TableView 标题上添加阴影,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48839965/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com