- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我搜索了一段时间,但无法弄清楚如何实现我找到的解决方案。
下面的帖子定义了我真正想要的东西,它也有一个解决方案,但在 objective-c 中。我尝试实现该解决方案,但实现后文本开始不显示。
UITextView bottom shadow on text
class AggrementView: UIView, UITextViewDelegate {
let acceptBtn = RippleButton()
let kvkkTextView = UITextView()
private let containerView = UIView()
override init(frame: CGRect) {
super.init(frame: frame)
setupUI()
setupConstraints()
}
public convenience init(text: String, imageName: String){
self.init()
}
public convenience init(text: String, imageName: String, senderColor: UIColor){
self.init()
}
required public init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
private func setupUI(){
self.backgroundColor = .clear
acceptBtn.translatesAutoresizingMaskIntoConstraints = false
//acceptBtn.backgroundColor = UIColor(red:0.40, green:0.69, blue:0.07, alpha:1.0)
acceptBtn.backgroundColor = UIColor.gray
acceptBtn.layer.cornerRadius = 6.0
acceptBtn.setTitle("Onaylıyorum", for: UIControlState.normal)
acceptBtn.titleLabel?.font = UIFont(name: "Corbert-Regular", size: 20)!
acceptBtn.setTitleColor(UIColor.flatWhite, for: UIControlState.normal)
//acceptBtn.setAllSideShadow(shadowShowSize: 8.0)
acceptBtn.accessibilityIdentifier = "acceptBtn"
acceptBtn.isEnabled = false
acceptBtn.setTitleColor(UIColor.lightGray, for: .disabled)
kvkkTextView.font = UIFont(name: "Corbert-Regular", size: 15)!
kvkkTextView.setContentOffset(CGPoint.zero, animated: false)
kvkkTextView.layer.cornerRadius = 6.0
kvkkTextView.backgroundColor = .clear
kvkkTextView.layer.borderColor = UIColor.flatGray.cgColor
kvkkTextView.textColor = UIColor.flatWhite
kvkkTextView.delegate = self
kvkkTextView.isEditable = false
containerView.backgroundColor = .clear
containerView.layer.cornerRadius = 6.0
self.addSubview(containerView)
containerView.addSubview(acceptBtn)
containerView.addSubview(kvkkTextView)
}
private func setupConstraints(){
containerView.anchor(self.topAnchor, left: self.leftAnchor, bottom: self.bottomAnchor, right: self.rightAnchor, topConstant: 90, leftConstant: 10, bottomConstant: 20, rightConstant: 10, widthConstant: 0, heightConstant: 0)
kvkkTextView.anchor(self.containerView.topAnchor, left: self.containerView.leftAnchor, bottom: self.acceptBtn.topAnchor, right: self.containerView.rightAnchor, topConstant: 0, leftConstant: 0, bottomConstant: 20, rightConstant: 0, widthConstant: 0, heightConstant: 0)
acceptBtn.anchor(nil, left: self.containerView.leftAnchor, bottom: self.containerView.bottomAnchor, right: self.containerView.rightAnchor, topConstant: 0, leftConstant: 10, bottomConstant: 10, rightConstant: 10, widthConstant: 0, heightConstant: 60)
}
func scrollViewDidScroll(_ scrollView: UIScrollView) {
if (scrollView.contentOffset.y >= scrollView.contentSize.height - scrollView.frame.size.height) {
print( "View scrolled to the bottom" )
UIView.animate(withDuration: 0.5) {
self.acceptBtn.backgroundColor = UIColor(red:0.40, green:0.69, blue:0.07, alpha:1.0)
self.acceptBtn.isEnabled = true
}
}
let color = UIColor.lightGray
guard
let verticalIndicator = scrollView.subviews.last as? UIImageView,
verticalIndicator.backgroundColor != color,
verticalIndicator.image?.renderingMode != .alwaysTemplate
else { return }
verticalIndicator.layer.masksToBounds = true
verticalIndicator.layer.cornerRadius = verticalIndicator.frame.width / 2
verticalIndicator.backgroundColor = color
verticalIndicator.image = verticalIndicator.image?.withRenderingMode(.alwaysTemplate)
verticalIndicator.tintColor = .clear
}
图片引用:@user2213271 UITextView bottom shadow on text发布
这是我试过的 gradientCode:
func applyShadow(){
var layerWidth: CGFloat = 8.0
var gl1 = CAGradientLayer()
var col1 = UIColor(red: 0.0, green: 0.0, blue: 0.0, alpha: 1.0).cgColor
var col2 = UIColor(red: 0.0, green: 0.0, blue: 0.0, alpha: 0.0).cgColor
gl1.colors = [col2, col1, col1, col2]
gl1.locations = [0.0, 0.0, 0.85, 1.0]
//underTextView - this is my UIView
gl1.frame = CGRect(x: 0, y: 0, width: underTextView.frame.width - layerWidth, height: underTextView.frame.height)
//layer for scrollIndicator - it must be visible always good
var gl2 = CAGradientLayer()
gl2.colors = [col1, col1]
gl2.locations = [0.0, 1.0]
gl2.frame = CGRect(x: underTextView.frame.width - layerWidth, y: 0, width: layerWidth, height: underTextView.frame.height)
//create main layer
var gl = CAGradientLayer()
gl.addSublayer(gl1)
gl.addSublayer(gl2)
//add to mask of UIView
underTextView.layer.mask = gl
}
最佳答案
您似乎忘记在设置 kvkkTextView
的 anchor 之前添加 kvkkTextView.translatesAutoresizingMaskIntoConstraints = false
。因此,您的 kvkkTextView
无法从约束中获取其框架。
关于ios - 在 Swift 中的 UITextView 上放置阴影,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51858023/
我有一个程序: [textView setFont:[UIFont fontWithName:@"ArialMT" size:20]]; [textVi
我正在 UITextViewDelegate 中处理代码。那里的每个函数都会接收接收事件的 UITextView 实例,例如: - (void)textViewDidBeginEditing:(UIT
我想在默认图像附件菜单选项(复制图像、保存到相机胶卷)中添加另一个菜单选项。请注意,如果 textView 未处于编辑模式,则当您长按嵌入在 UITextView 中的图像时会显示这些选项。 我已经尝
我想尝试禁用 UITextTapRecognizer,我认为它是 UITextView 的内置属性,因为我怀疑它会干扰我想要实现的点击手势识别器。这怎么可能? 感谢阅读! 最佳答案 我不确定这是否直接
首先我使用这个 UITextView 类 TextView 类.h @interface textViewClass : UITextView TextView 类.m @implementation
我正在开发一个应用程序,我需要为大文本放置一个 UITextView。我有一个尺寸为 180X89 的背景图像(与 UITextView 框架大小相同)。当将图像放在 UITextView 后面时,一
我只是想在 UITextView 中输入一些默认文本。有几个段落,我想用一个新行分隔这些段落。但是,当我按回车时,它只是完成了数据的输入。 在界面生成器中为 UITextView 创建默认文本时,如何
我的 iPhone 应用程序中有两个 UITextView。当用户选择一个 UITextView 时, Controller 会自动转到另一个 UITextView。我在我的项目中尝试了以下方式。但是
我正在使用 UITextView 并在我的代码中分配一些文本,但出于某种原因,它总是在 5-6 行之后开始。 UITextView 是一个 AttributedTextView 或允许属性字符串。
我有一个自定义 UIView,我想在其中布局一组 UITextView 以响应 AJAX 调用。所以我想我需要在代码中创建这些。我目前将位置设置为固定位置,但宁愿将其设置为比前一个位置低 20 像素。
我正在开发一个应用程序,它具有动态添加 TextView 的功能,在我们拖动它时增加和减小它的大小。 我可以根据字符数调整 TextView 大小,方法是将 TextView 的内容大小设置为 Tex
这可能是个愚蠢的问题。我正在尝试像所附图片一样设置左/右页边距。我通过在UIScrollView中添加UITextView成功实现了。但是,我几乎可以单独使用 UITextView 实现我想要的一切。
我有一个 UITextView。我正在根据方法 textViewDidChange 中文本的大小调整 TextView 的大小。这在我打字时工作正常。但是当我粘贴一些东西时,这不会接到电话。这是预期的
我正在开发一个基于消息的 iPhone 应用程序。我有一个屏幕可以回复收到的消息。此屏幕包含两个 UITextView,如 bottomTextView 和 topTextView。 topTextV
我用 View 制作了一个 UITextview 自定义控件。它工作正常。当我输入新行时, TextView 会随着 View (深蓝色)而增加。此后 TextViell 将以滚动的形式工作。 代码是
我想在用户完成编辑并点击屏幕上的其他地方后对我的 UITextView 执行一些处理。最佳做法是什么? 我几乎设法通过 func textViewDidEndEditing(textView: UIT
我想更改富 UITextView (iOS 6) 的部分或全部属性文本,并允许用户撤消更改。 看完NSUndoManager documentation ,我尝试了第一种方法: “Simple und
当我在 IOS7 模拟器上测试我的应用程序时。 有时我在使用 sizeToFit 时发现它很奇怪的 UITextView .sizeToFit后的框架看起来是对的,但文字只能部分显示,就像下面的照片一
我想要一个 tablew View ,其行为类似于 Apple 的 iPhone 联系人应用程序:一个 uitableviewcell,里面有一个 uitextview,这样当我在 uitextvie
我有一个可编辑的 UITextView,然后是一个仅供选择的 UITextView。当我在第一个 UITextView 中写东西时,有时我想引用另一个 UITextView 来复制文本,然后将其粘贴到
我是一名优秀的程序员,十分优秀!