在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 } }); }
相关问答
更多-
测量收到的流量(Measuring traffic sent received)[2021-11-12]
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 ...
-
无法创建TabLayout(Unable create TabLayout)[2023-09-28]
您应首先在依赖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' -
测量文本问题的宽度(Measuring width of text issue)[2023-10-26]
在对我的代码进行一些更改之后,我终于得到了解 private float calcWidthSize(CharSequence cha, float currentSize) { TextPaint paint = new TextPaint(); paint.setTextSize(currentSize); return paint.measureText(cha, 0, cha.length()); } currentSize之前直接设置,然后我通 ... -
用Java测量时间(Measuring time in Java)[2022-08-30]
对于基本计时,您可以使用Guava的Stopwatch类 (如果您不想拉入整个Guava库,只需抓住它的源代码)。 要获得更完整的基准测试解决方案,请参阅同一团队的Caliper 。 这两者都基于System.nanoTime() ,您应该比System.currentTimeMillis()更喜欢测量已用时间。 为什么System.currentTimeMillis()是一个“时钟”(它试图返回墙壁时间),而System.nanoTime()是一个“计时器”(它试图从某个任意点返回时间)的基本原因。 当你 ... -
用iPhone测量房间(Measuring a room with an iPhone)[2022-02-07]
从麦克风发出声音并测量它们返回的时间。 有些应用程序已经这样做了,例如PocketMeter。 我怀疑这不会是用户友好的,并且比实际更噱头。 Au对应,monfrère。 这是用户最友好的,更不用说准确的测量房间尺寸的方法。 PocketMeter以半英寸的精度测量到一面墙的距离。 如果您使用相同的公式来测量距离,但让人站在房间的一个角落(以便到墙壁,地板和天花板的距离都不同),您应该能够计算所有三个测量值(长度,宽度和高度)与一个声纳脉冲。 编辑,因为评论,补充: 在理想的世界中,你会得到6个脉冲,每个表 ... -
测量像素(measuring pixels)[2023-05-13]
我怀疑当你实现一个工具来做到这一点时,你可以通过跟踪和错误的方法来完成它。 当我不得不做同样的事情时(像你一样使用iTextSharp),我开始试图将文本写入表单上的任意位置,比如x = 100,y = 100。当我看到它在PDF上的位置时,我调整了。 做完这一点之后,你会了解下一点应该在哪个坐标上。 技巧#1: 请记住0,0引用文档的左下角 。 随着这些数字的增加,你的位置在文档中向右上移。 提示#2: 想想你的PDF上的内容在垂直和水平轴上的排列方式。 找到这些值并在程序中将它们声明为常量,并在代码中引 ... -
TabLayout测量(TabLayout measuring)[2022-12-29]
在充气和测量后测量视图。 使用ViewTreeObserver : tabLayout.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { if (Build.V ... -
TabLayout如何工作?(How does TabLayout work?)[2022-09-22]
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 ...