[英]How to implement a draggable MKPointAnnotation using Swift (IOS)?
[英]how to implement marquee label in IOS using swift
要在 swift 中創建選框,請在您的項目中添加下面的類https://github.com/cbpowell/MarqueeLabel
為此,首先添加 pod: pod 'MarqueeLabel'
。
並在您的項目中執行pod update
。
然后在您的工作文件中導入 pod: import MarqueeLabel
創建一個標簽並將自定義類設置為故事板中的MarqueeLabel
。 然后:
@IBOutlet weak var marqueeLabel:MarqueeLabel!
在 ViewDidLoad 中添加:
marqueeLabel.type = .Continuous
marqueeLabel.scrollDuration = 5.0
marqueeLabel.animationCurve = .EaseInOut
marqueeLabel.fadeLength = 10.0
marqueeLabel.leadingBuffer = 30.0
marqueeLabel.trailingBuffer = 20.0
使用MarqueeLabel ,它非常易於使用和實現。
如果您正在使用 Pod,那么您可以集成並嘗試以下示例代碼:
目標-C:
pod 'MarqueeLabel'
MarqueeLabel *lengthyLabel = [[MarqueeLabel alloc] initWithFrame:aFrame duration:8.0 andFadeLength:10.0f];
迅速:
pod 'MarqueeLabel/Swift'
var lengthyLabel = MarqueeLabel.init(frame: aFrame, duration: 8.0, fadeLength: 10.0)
使用 Web 視圖的另一種解決方案:
String marquee = "<html><body><marquee>This is sample marquee</marquee></body></html>"
webview.loadData(marquee, "text/html", null);
這是結果:
下載以下鏈接github Marquee標簽Demo:
https://github.com/cbpowell/MarqueeLabel-Swift
然后
請按照以下步驟操作:
下載上面的github項目
從類中復制 Marqueelabel.swift 文件
將 Marqueelabel.swift 文件粘貼到您的項目中
將您的任何 UILabel 指定為 MarqueeLabel 類型
例如:@IBOutlet 弱變量 demoLabel1:MarqueeLabel!
運行你的項目
使用可以將其內容選中的標簽非常簡單。 只需在您的項目中添加MarqueeLabel pod。
迅速:
pod 'MarqueeLabel/Swift'
然后選擇您希望對其執行選取框的標簽,並在身份檢查器中向其添加自定義類 MarqueeLabel。
就是這樣。
這是在標簽中添加選取框的最簡單方法。 添加自定義類 MarqueeLabel 后,如果您希望標簽內容的最后一個字符和第一個字符之間有一些間距,則:
第一步:選擇標簽。
第 2 步:轉到 Attributes Inspector,然后將fadeLength 屬性值增加到您想要的程度。 對它應用值 10 就足夠公平了。
如果您希望自定義更多,則將自定義類 MarqueeLabel 添加到標簽,然后在您的代碼中獲取該標簽的出口,並按照您想要的方式對其進行自定義。
代碼中該標簽的出口應如下所示:
@IBOutlet var YOURLABELNAME: MarqueeLabel!
如果不是這樣,那么首先將自定義類添加到標簽,然后在代碼文件中獲取其出口,然后重新開始。
在 Apple tvOS 中使用 MarqueeLabel 設置這樣的速度
https://github.com/cbpowell/MarqueeLabel
之前在我的項目中設置的速度
videoTitleLabel.speed =.duration(25.0)
現在我把 25.0 改成了 10
videoTitleLabel.speed =.duration(10)
現在它移動位速度
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.