首页 \ 问答 \ 在UITextField中添加UIButton(Adding an UIButton inside an UITextField)

在UITextField中添加UIButton(Adding an UIButton inside an UITextField)

我想在我的UITextField中添加一个带有文本“...”的按钮。 我正在尝试的是以下内容:

@IBOutlet weak var requestTitleTxtField: UITextField!

viewDidLoad中():

var detailsButton = UIButton()
detailsButton.titleLabel!.text = "..."
requestTitleTxtField.rightViewMode = UITextFieldViewMode.Always
requestTitleTxtField.rightView = detailsButton

这不会返回任何错误消息,但也不显示按钮。


I want to add a button with text "..." inside my UITextField. What i'm trying is the following:

@IBOutlet weak var requestTitleTxtField: UITextField!

viewDidLoad():

var detailsButton = UIButton()
detailsButton.titleLabel!.text = "..."
requestTitleTxtField.rightViewMode = UITextFieldViewMode.Always
requestTitleTxtField.rightView = detailsButton

This is not returning any error message but isn't showing the button either.


原文:https://stackoverflow.com/questions/32443373
更新时间:2023-08-27 13:08

最满意答案

在充气和测量后测量视图。 使用ViewTreeObserver

tabLayout.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                    @Override
                    public void onGlobalLayout() {
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                            tabLayout.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                        } else {
                            tabLayout.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                        }
                        //measure your views
                    }
                });
            }

Measure view after they are inflated and measured. Use ViewTreeObserver for that:

tabLayout.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                    @Override
                    public void onGlobalLayout() {
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                            tabLayout.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                        } else {
                            tabLayout.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                        }
                        //measure your views
                    }
                });
            }

相关问答

更多
  • Clientside解决方案:如果你使用的是firefox,那么addon firebug( https://addons.mozilla.org/de/firefox/addon/firebug/ )可以做到这一点。 Serverside解决方案:您可以在apache日志格式中指定以下内容(对于您的访问日志): %...B: Bytes sent, excluding HTTP headers. %...b: Bytes sent, excluding HTTP hea ...
  • 启动分析器 SET profiling = 1; 然后执行你的查询。 同 SHOW PROFILES; 您将看到Profiler具有统计信息的查询列表。 最后你选择要查询的查询 SHOW PROFILE FOR QUERY 1; 或您查询的任何数字。 你得到的是一个列表,查询中花费了多少时间。 手册中的更多信息。 Start the profiler with SET profiling = 1; Then execute your Query. With SHOW PROFILES; you s ...
  • 您应首先在依赖app.gradle下的app.gradle导入设计支持库 compile 'com.android.support:design:23.4.0' You shall import the design support library first in your app.gradle under dependencies compile 'com.android.support:design:23.4.0'
  • 在对我的代码进行一些更改之后,我终于得到了解 private float calcWidthSize(CharSequence cha, float currentSize) { TextPaint paint = new TextPaint(); paint.setTextSize(currentSize); return paint.measureText(cha, 0, cha.length()); } currentSize之前直接设置,然后我通 ...
  • 对于基本计时,您可以使用Guava的Stopwatch类 (如果您不想拉入整个Guava库,只需抓住它的源代码)。 要获得更完整的基准测试解决方案,请参阅同一团队的Caliper 。 这两者都基于System.nanoTime() ,您应该比System.currentTimeMillis()更喜欢测量已用时间。 为什么System.currentTimeMillis()是一个“时钟”(它试图返回墙壁时间),而System.nanoTime()是一个“计时器”(它试图从某个任意点返回时间)的基本原因。 当你 ...
  • 从麦克风发出声音并测量它们返回的时间。 有些应用程序已经这样做了,例如PocketMeter。 我怀疑这不会是用户友好的,并且比实际更噱头。 Au对应,monfrère。 这是用户最友好的,更不用说准确的测量房间尺寸的方法。 PocketMeter以半英寸的精度测量到一面墙的距离。 如果您使用相同的公式来测量距离,但让人站在房间的一个角落(以便到墙壁,地板和天花板的距离都不同),您应该能够计算所有三个测量值(长度,宽度和高度)与一个声纳脉冲。 编辑,因为评论,补充: 在理想的世界中,你会得到6个脉冲,每个表 ...
  • 我怀疑当你实现一个工具来做到这一点时,你可以通过跟踪和错误的方法来完成它。 当我不得不做同样的事情时(像你一样使用iTextSharp),我开始试图将文本写入表单上的任意位置,比如x = 100,y = 100。当我看到它在PDF上的位置时,我调整了。 做完这一点之后,你会了解下一点应该在哪个坐标上。 技巧#1: 请记住0,0引用文档的左下角 。 随着这些数字的增加,你的位置在文档中向右上移。 提示#2: 想想你的PDF上的内容在垂直和水平轴上的排列方式。 找到这些值并在程序中将它们声明为常量,并在代码中引 ...
  • 在充气和测量后测量视图。 使用ViewTreeObserver : tabLayout.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { if (Build.V ...
  • ViewPager将相邻的片段保存在内存中,以便在页面之间快速转换。 我认为重新创建的片段有一个修复(因为你将它们存储在一个列表中,添加不是自己多次创建它们)。 应用程序启动时,此过程发生: 我不确定onCreate#1加倍,但片段1和2已经启动 onCreate Fragment 1 onCreate Fragment 1 onActivityCreated Fragment 1 onResume Fragment 1 onActivityCreated Fragment 2 onResume Fragm ...
  • 在您希望TabLayout不显示的片段中... tabLayout.setVisibility(View.GONE); 我会将上面的部分代码放在片段的onCreateView()方法中。 然后,在您希望它再次显示的片段中: tabLayout.setVisibility(View.VISIBLE); In the fragments that you want your TabLayout to not show... tabLayout.setVisibility(View.GONE); I wou ...

相关文章

更多

最新问答

更多
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)
  • 是否可以嵌套hazelcast IMaps?(Is it possible to nest hazelcast IMaps? And whick side effects can I expect? Is it a good Idea anyway?)
  • UIViewAnimationOptionRepeat在两个动画之间暂停(UIViewAnimationOptionRepeat pausing in between two animations)
  • 在x-kendo-template中使用Razor查询(Using Razor query within x-kendo-template)
  • 在BeautifulSoup中替换文本而不转义(Replace text without escaping in BeautifulSoup)
  • 如何在存根或模拟不存在的方法时配置Rspec以引发错误?(How can I configure Rspec to raise error when stubbing or mocking non-existing methods?)
  • asp用javascript(asp with javascript)
  • “%()s”在sql查询中的含义是什么?(What does “%()s” means in sql query?)
  • 如何为其编辑的内容提供自定义UITableViewCell上下文?(How to give a custom UITableViewCell context of what it is editing?)
  • c ++十进制到二进制,然后使用操作,然后回到十进制(c++ Decimal to binary, then use operation, then back to decimal)
  • 以编程方式创建视频?(Create videos programmatically?)
  • 无法在BeautifulSoup中正确解析数据(Unable to parse data correctly in BeautifulSoup)
  • webform和mvc的区别 知乎
  • 如何使用wadl2java生成REST服务模板,其中POST / PUT方法具有参数?(How do you generate REST service template with wadl2java where POST/PUT methods have parameters?)
  • 我无法理解我的travis构建有什么问题(I am having trouble understanding what is wrong with my travis build)
  • iOS9 Scope Bar出现在Search Bar后面或旁边(iOS9 Scope Bar appears either behind or beside Search Bar)
  • 为什么开机慢上面还显示;Inetrnet,Explorer
  • 有关调用远程WCF服务的超时问题(Timeout Question about Invoking a Remote WCF Service)