uibutton位置位于swift的textview的右下角

发布于 2025-01-31 00:04:37 字数 914 浏览 2 评论 0原文

我有一个自定义类uiview,其中我有一个文本视图。而且我正在尝试使用AutororesizingMask编程地将Uibutton添加到textView的右下角。这是我的代码:

public init() {
textViewButton = UIButton(type: .custom)
     textViewButton.addTarget(self, action: #selector(didPressButton), for: .touchUpInside)
     textViewButton.autoresizingMask = [.flexibleTopMargin, .flexibleRightMargin, .flexibleLeftMargin]
     self.addSubview(textViewButton)
     textViewButton.isHidden = true
}

我在LayoutsUbViews中设置帧:

override public func layoutSubviews() {
     super.layoutSubviews()
textViewButton.frame = CGRect(x: bounds.maxX - 50, y: 0, width: 50, height: 50)
}

这是使用我的代码的按钮的当前位置: 这是带有空文本的当前位置 这是我代码的当前位置

我如何将按钮固定到textView的右下角?

I have a custom class UIView in which i have a textView. And I'm trying to add UIButton to bottom right corner of textView programmatically using autoresizingMask.This is my code:

public init() {
textViewButton = UIButton(type: .custom)
     textViewButton.addTarget(self, action: #selector(didPressButton), for: .touchUpInside)
     textViewButton.autoresizingMask = [.flexibleTopMargin, .flexibleRightMargin, .flexibleLeftMargin]
     self.addSubview(textViewButton)
     textViewButton.isHidden = true
}

And I'm setting frame in layoutSubviews:

override public func layoutSubviews() {
     super.layoutSubviews()
textViewButton.frame = CGRect(x: bounds.maxX - 50, y: 0, width: 50, height: 50)
}

This is the current position of the button with my code:
This is the current position with empty text
This is the current position with my code

How do I fix the button to bottom right corner of textView?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文