我正在网上上课,其中一个项目是创建一个标签.
在Xcode中,我将它集中在垂直和水平轴上,但是当我运行模拟器时,它总是在右侧,而不是居中.我甚至尝试过其他模拟手机.
这也发生在文本字段中.
我真的不确定是什么问题,因为在Xcode中它正确显示.
我需要UITableViewCell根据它的内容设置动态高度.
这是我的演示图片:
在这个标签中有动态内容所以根据标签内容,我的单元格高度应该改变..
我得到了约束错误.在这个单元格中,有两个UILabel可用,并且都具有动态内容大小.(我已经使用只有一个标签的自动调整大小的单元格进行了演示.)但是在这个单元格中有两个标签.所以错误是xcode建议我给Y POS或Height标签,但我已经设置了顶级约束.(标签线设置为0的4个侧面约束)但是它仍然失败.我也尝试使用此代码
self.tableView.estimatedRowHeight = 250.0;
self.tableView.rowHeight = UITableViewAutomaticDimension;
Run Code Online (Sandbox Code Playgroud)
这是我的演示代码
我是Swift的新手。我收到此错误:
无法分配给属性:“ width”是仅获取属性
使用此语句时:
cell.reciverMsg.frame.width = cell.reciverMsg.text?.characters.count * 2
Run Code Online (Sandbox Code Playgroud)
reciverMsg是一个UILabel。
标签位于屏幕中央(或下方),iphone 4.3不显示.但iphone与iOS 5.0显示.全部由IB制造.
UPD :(代码)
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.view.backgroundColor = [UIColor blackColor];
[scroll setContentSize:CGSizeMake(320, 700)];
scroll.frame = CGRectMake(0, 0, 320, 460);
}
return self;
}
Run Code Online (Sandbox Code Playgroud) 可能重复:
如何在字符串中转义双引号?
我需要在@""里面打印一个"abc"
我目前的字符串是
[displayLbl setText:@"press stop"];
Run Code Online (Sandbox Code Playgroud)
但是我需要:
[displayLbl setText:@"press "stop""];
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?
我在UIView中添加了Label并创建了它的插座,然后在UITapGestureRecognizer的帮助下我添加了功能,但是当我点击或点击标签时.标签文本不会更改.我搜索了类似的问题,我得到的答案也是我写的,但标签文字仍未改变.用Swift 3.0编写的代码.这是我写的代码 -
import UIKit
class testingViewController: UIViewController {
@IBOutlet weak var testLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
let tap:UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(showDatePicker))
tap.numberOfTouchesRequired = 1
tap.numberOfTapsRequired = 1
testLabel.addGestureRecognizer(tap)
testLabel.isUserInteractionEnabled = true// after adding this it worked
// Do any additional setup after loading the view.
}
func showDatePicker(){
print("testing")
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
/*
// MARK: - Navigation
// In a storyboard-based application, …Run Code Online (Sandbox Code Playgroud) 请检查这个我需要解释为什么 texField.text!不崩溃和 label.text! 崩溃
而且我们知道 UITextField有财产open var text:String? 和UILabel拥有 open var text:String?
let texField = UITextField()
texField.text = nil
print(texField.text!) // not crash
let label = UILabel()
label.text = nil
print(label.text!) //crash
Run Code Online (Sandbox Code Playgroud) 当我点击按钮 UILabel 出现并立即再次消失。我需要它在几秒钟后消失。这是我的第一个应用程序,我无法解决这个问题。谢谢!
func done() {
if sauserImageView.isHidden == false && cupImageView.isHidden == false && spoonImageView.isHidden == false {
winningLabel.isHidden = false
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个由 - 组成的字符串 -
lblWithText.backgroundColor = [UIColor clearColor];
lblWithText.textColor = [UIColor blackColor];
lblWithText.font = [UIFont fontWithName:@"Helvetica" size:12.0];
lblWithText.text = [NSString stringWithFormat:@"Blah1:blah-blah%d. Blah2:-%d%%", [currentCoupon.couponPrice intValue],[currentCoupon.couponDiscountPercent intValue]];
Run Code Online (Sandbox Code Playgroud)
请告诉我怎么做"Blah2: - %d %%""是Bolden?先谢谢你
对于一些人来说,我的问题可能很简单,但我对Objective C和Xcode相对较新.所以我有一个UILabel,我正在运行一个if语句,询问UILabel是否等于self.NSString然后执行...这是代码.
if (UILabel.text == self.NSString)
{
//Do Something here...
}
Run Code Online (Sandbox Code Playgroud)
我想知道这是否有效,或者我必须做些什么才能让它开始工作.提前致谢.
我想在我的ios项目中创建一个按钮.
此按钮适用于1到200(或任何以上)的计数
每次按下按钮,标签都会增加
第一次单击时,第二次单击时标签= 1,标签= 2...
我创建了一个按钮和一个标签.
按钮IBAction我该怎么办?
uilabel ×13
ios ×8
objective-c ×6
swift ×4
cocoa-touch ×3
iphone ×2
if-statement ×1
ios4 ×1
ipad ×1
nsstring ×1
string ×1
swift3 ×1
uibutton ×1
uikit ×1
uiscrollview ×1
uitableview ×1
uitextfield ×1
xcode7 ×1