Xcode 15 beta 不附带 iOS 17 的设备支持文件。我们可以通过任何其他方式在 Xcode 14 上运行 iOS 17 设备
要在静音模式下播放声音我使用以下方法.但它是如何不起作用的.
// Works on Swift 3
do {
try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback)
} catch {
print(error)
}
Run Code Online (Sandbox Code Playgroud)
如何让它在4.2/iOS 12中运行?
在较新的版本中,我们需要设置模式和选项.
try AVAudioSession.sharedInstance().setCategory(
<#T##category:AVAudioSession.Category##AVAudioSession.Category#>,
mode: <#T##AVAudioSession.Mode#>,
options: <#T##AVAudioSession.CategoryOptions#>)`
Run Code Online (Sandbox Code Playgroud) 我想像Back Button一样显示Next Button但是rightBarButton不会像后面的barButton那样触摸到屏幕的末尾.
let button = UIButton(type: .system)
button.setImage(UIImage(named: "ic_next_button"), for: .normal) // 22x22 1x, 44x44 2x, 66x66 3x
button.setTitle("Next", for: .normal)
button.sizeToFit()
button.transform = CGAffineTransform(scaleX: -1.0, y: 1.0)
button.titleLabel?.transform = CGAffineTransform(scaleX: -1.0, y: 1.0)
button.imageView?.transform = CGAffineTransform(scaleX: -1.0, y: 1.0)
self.navigationItem.rightBarButtonItem = UIBarButtonItem(customView: button)
Run Code Online (Sandbox Code Playgroud)
HTML5
从url 加载页面时,我在该页面的某个地方获取pdf,我必须下载该pdf或将其另存为base64
.
这是pdf在HTML代码中的位置.我不能简单地点击'src'网址并获得pdf.
< embed width="100%" height="100%" name="plugin" id="plugin" src="https://myurl.com/fileToOpen.pdf” type="application/pdf" internalinstanceid="8" title="">
Run Code Online (Sandbox Code Playgroud)
任何JS可以帮助我获取该base64
字符串或任何其他方法下载?
我的导航栏右侧有两个按钮.
extension UIViewController {
func setNavigationBarItem() {
let profileButton = UIBarButtonItem(title: "?", style: .plain, target: self, action: #selector(didTapProfileButton(_:)))
navigationItem.rightBarButtonItems = [addRightBarButtonWithImage(UIImage(named: "menu")!), profileButton]
self.slideMenuController()?.removeRightGestures()
self.slideMenuController()?.addRightGestures()
}
}
Run Code Online (Sandbox Code Playgroud)
我创建了2个这样的按钮.但我想要的profileButton是背景颜色,并具有该按钮的圆角半径.如何添加它使它看起来像:
忽略黑色部分.UIBarButton
将是黄色背景和角半径.
当用户单击后退按钮时,我想显示带有确认的警报。这就是我尝试添加动作的方式。
self.navigationItem.hidesBackButton = true
let newBackButton = UIBarButtonItem(title: "<", style: UIBarButtonItemStyle.plain, target: self, action: #selector(ViewController.save(sender:)))
self.navigationItem.leftBarButtonItem = newBackButton
Run Code Online (Sandbox Code Playgroud)
这工作正常,但我想要默认的后退按钮图像而不是自定义标题。怎么做 ?
我也尝试了以下代码:
self.navigationItem.backBarButtonItem?.action = #selector(ViewController.save(sender:))
Run Code Online (Sandbox Code Playgroud)
...但动作也没有执行。
如何在文本右侧添加文本和图像UITextField
.我有一个UITextField
最初会在其右边有一个文本/标签,当用户点击按钮时,它textField
现在将在右边有文字+图像UITextField
可以像这样添加图像,但是文本/标签又是什么呢?
txtField.rightViewMode = .always
txtField.rightView = UIImageView(image: UIImage(named: "selectdrop"))
Run Code Online (Sandbox Code Playgroud) 我正在使用“ QLPreviewController”显示文档文件(pdf / doc)。有什么方法可以获取总页数以及当前页数吗?
像“ 9之9”一样-如何获得
*** 由于未捕获的异常“NSObjectNotAvailableException”而终止应用程序,原因:“UIAlertView 已弃用且不可用于基于 UIScene 的应用程序,请使用 UIAlertController!”
从 WKWebView 发出警报时,它会引发上述错误。
UIAlertView 是从网页中的 Javascript 调用的。我没有手动调用 UIAlertView。
import UIKit
import WebKit
class ViewController: UIViewController{
@IBOutlet weak var webView: WKWebView!
override func viewDidLoad() {
super.viewDidLoad()
let url = URL(string: "https://www.google.com/maps")!
webView.load(URLRequest(url: url))
}
}
Run Code Online (Sandbox Code Playgroud)
当我单击“您的位置”时加载地图后,应用程序崩溃。
我试图Timer
在用户按下后退按钮时取消初始化/无效,但在他按下下一个ViewController时不尝试取消初始化/无效。
var timer = Timer()
timer = Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: #selector(timePrinter), userInfo: nil, repeats: true)
timer.fire()
override func viewWillDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
if self.isMovingFromParentViewController{
timer.invalidate()
}
}
Run Code Online (Sandbox Code Playgroud)
当用户按下返回按钮时,它不起作用。
private func setTitle(title:String, subtitle:String, animate: Bool) -> UIView {
let titleLabel = UILabel(frame: CGRect(x:0, y:-5, width:0, height:0))
titleLabel.backgroundColor = UIColor.clear
titleLabel.textColor = UIColor.gray
titleLabel.font = UIFont.boldSystemFont(ofSize: 15)
titleLabel.text = title
titleLabel.adjustsFontSizeToFitWidth = true
let subtitleLabel = UILabel(frame: CGRect(x:0, y:18, width:0, height:0))
subtitleLabel.backgroundColor = UIColor.clear
subtitleLabel.textColor = UIColor.black
subtitleLabel.font = UIFont.systemFont(ofSize: 12)
subtitleLabel.text = subtitle
subtitleLabel.adjustsFontSizeToFitWidth = true
let titleView = UIView(frame: CGRect(x:0, y:0, width:max(titleLabel.frame.size.width, subtitleLabel.frame.size.width), height:30))
let titleViewTapGesture = UITapGestureRecognizer(target: self, action: #selector(titleViewTapped(sender:)))
titleView.addGestureRecognizer(titleViewTapGesture)
titleView.addSubview(titleLabel)
if animate{
subtitleLabel.alpha = 0.0 …
Run Code Online (Sandbox Code Playgroud) 下面是我从WKWebView中加载的URL获取的标记之一
<img id ="image_id"name ="imageName"src ="captcha.jpg">
在DidFinish是否可以将该图像作为UIImage?
我正在尝试通过以下方式将水平渐变添加到 UIView
extension UIView {
func insertHorizontalGradient(_ color1: UIColor, _ color2: UIColor) {
let gradient = CAGradientLayer()
gradient.colors = [color1.cgColor, color2.cgColor]
gradient.transform = CATransform3DMakeRotation(CGFloat.pi / 2, 0, 0, 1)
gradient.frame = bounds
layer.insertSublayer(gradient, at: 0)
}
}
if let color1 = UIColor(hexString: "364190"), let color2 = UIColor(hexString: "699cf5"){
self.statusBarView.insertHorizontalGradient(color1, color2)
}
if let color1 = UIColor(hexString: "182395"), let color2 = UIColor(hexString: "5497f0"){
self.navigationBarView.insertHorizontalGradient(color1, color2)
}
Run Code Online (Sandbox Code Playgroud)
但在 iPhone 6Plus 上,它没有应用于整个 UIView。但在 iPhone 6 上就完美了。
ios ×13
swift ×12
swift3 ×3
wkwebview ×2
avfoundation ×1
ios13 ×1
ios17 ×1
javascript ×1
nstimer ×1
quicklook ×1
uialertview ×1
uilabel ×1
uitextfield ×1
uiview ×1
xcode ×1
xcode15 ×1