I would like to make a UIView
highlighted after it's pressed and return to the normal color after release. What is the best practise for doing this?
相关问题
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
- “Zero out” sensitive String data in Swift
- SwiftUI: UIImage (QRCode) does not load after call
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- Using if let syntax in switch statement
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- Enum with associated value conforming to CaseItera
- Swift - hide pickerView after value selected
- Is there a Github markdown language identifier for
Subclass the
UIView
and keep your view controller lean.Apple about overriding
touchesBegan
andtouchesEnded
:This example only illustrates your question. Subclassing
UIView
can become relatively involved so here are a couple of good starting points:https://developer.apple.com/documentation/uikit/uiview
Proper practice for subclassing UIView?
Very simple example - you can run it in a Playground page:
In practice, though, you want some additional code to check state, handle
touchesCancelled
, etc.This is just to get you going - read up on touch events at: https://developer.apple.com/documentation/uikit/uiview