我在我的应用中有推送通知.每当启动应用程序时,我都想检查用户是否为我的应用程序启用了推送通知.
我是这样做的:
let notificationType = UIApplication.sharedApplication().currentUserNotificationSettings()!.types
if notificationType == UIUserNotificationType.None {
print("OFF")
} else {
print("ON")
}
Run Code Online (Sandbox Code Playgroud)
如果用户禁用推送通知,有没有办法从我的应用程序激活此功能?
或者有没有其他选择将用户发送到推送通知设置(设置 - 通知 - AppName)?
按下按钮后,我想以编程方式从实际位置+ 20左边距离移动文本字段.
这是我的xml文件:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="5dp"
android:paddingBottom="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/txtField"
android:layout_below="@+id/txtField2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="20dp"
android:layout_toLeftOf="@+id/Seperator"
android:layout_toStartOf="@+id/Seperator"
android:layout_marginRight="10p" />
....
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
我试过这段代码:
parameter = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
parameter.setMargins(30, 32, 10, 0); // left, top, right, bottom
txtField.setLayoutParams(parameter);
Run Code Online (Sandbox Code Playgroud)
这是半最优的.有没有办法使用xml文件的所有值,只能以编程方式更改左边距值?
早上好,
我有一个带有德语和英语 xml 文件的 android 应用程序。现在我想像这样设置和文本视图:
“你好用户 x,你好世界 y。” “你好 Benutzer x,你好贴边 y。”
对于 x 和 yi 想设置一个变量。我如何使用动态变量为两种语言翻译此文本?
在我的swift 2应用程序中,我可以生成如下QR码:
let data = "1234567890".dataUsingEncoding(NSISOLatin1StringEncoding, allowLossyConversion: false)
let filter = CIFilter(name: "CIQRCodeGenerator")
filter!.setValue(data, forKey: "inputMessage")
filter!.setValue("Q", forKey: "inputCorrectionLevel")
qrcodeImage = filter!.outputImage
let transformedImage = qrcodeImage.imageByApplyingTransform(CGAffineTransformMakeScale(150, 150))
QRCodeImage.image = UIImage(CIImage: transformedImage)
Run Code Online (Sandbox Code Playgroud)
但我的QR码得到一个白色的背景图像,但我希望有一个透明的背景.
我试过这样的事情:
QRCodeImage.backgroundColor = UIColor.clearColor()
Run Code Online (Sandbox Code Playgroud)
但这不起作用.任何的想法 ?:)
在我的swift应用程序中,我有一个像这样的搜索栏:
lazy var searchBar = UISearchBar(frame: CGRectMake(0, 0, 0, 0))
searchBar.delegate = self
searchBar.showsCancelButton = true
searchBar.tintColor = UIColor.blackColor()
searchBar.spellCheckingType = .No
searchBar.autocapitalizationType = .None
searchBar.autocorrectionType = .No
searchBar.placeholder = "Suchbegriff eingeben ..."
searchBar.sizeToFit()
Run Code Online (Sandbox Code Playgroud)
如何为取消按钮设置另一种色调颜色作为整个搜索栏的色调?
我必须修改我的swift 2应用程序的for循环.目前我使用这种语法
for (var x = 0; x < 5; x++) {
Run Code Online (Sandbox Code Playgroud)
我知道我必须使用这个:
for x in 0..<5 {
Run Code Online (Sandbox Code Playgroud)
但我如何改变这个循环:
for (var x = 0; x < 6; x = x+2) {
Run Code Online (Sandbox Code Playgroud) 在我的应用中,我设置了如下搜索器:
searchBar.delegate = self
searchBar.showsCancelButton = true
searchBar.tintColor = UIColor.whiteColor()
searchBar.spellCheckingType = .No
searchBar.autocapitalizationType = .None
searchBar.autocorrectionType = .No
searchBar.returnKeyType = .Done
searchBar.sizeToFit()
let view: UIView = self.searchBar.subviews[0] as UIView
for subView: UIView in view.subviews {
if subView.isKindOfClass(UITextField){
subView.tintColor = UIColor.greenColor()
}
}
Run Code Online (Sandbox Code Playgroud)
此代码部分为我的“取消”按钮设置了白色文本颜色,为我的搜索字段设置了绿色。
如您所见,光标将为绿色,但文本颜色为黑色。我怎么了