Skip to content

Instantly share code, notes, and snippets.

View sTinGe's full-sized avatar
🐶
howl~

Wei-Long Su sTinGe

🐶
howl~
View GitHub Profile
// avoid ambiguous position by using wrapper
let wrapper = UIView()
let view = HeaderView()
view.translatesAutoresizingMaskIntoConstraints = false
wrapper.addSubview(view)
NSLayoutConstraint.activate([
view.leftAnchor.constraint(equalTo: wrapper.leftAnchor),
view.rightAnchor.constraint(equalTo: wrapper.rightAnchor),
view.topAnchor.constraint(equalTo: wrapper.topAnchor),
view.bottomAnchor.constraint(equalTo: wrapper.bottomAnchor),
NSLayoutConstraint.activate([
play.rightAnchor.constraint(
equalTo: guide_mark.leftAnchor,
constant: -8
)
])
// add constraints through Autolayout Visual Format Language
view.addConstraints(
NSLayoutConstraint.constraints(
withVisualFormat: "H:|-50-[button]",
options: .alignAllTop,
metrics: nil,
views: objects
)
)
// UIViewController
let constraints = [
view.centerXAnchor.constraint(equalTo: superview.centerXAnchor),
view.centerYAnchor.constraint(equalTo: superview.centerYAnchor),
view.widthAnchor.constraint(equalTo: superview.widthAnchor)
view.heightAnchor.constraint(equalTo: superview.heightAnchor),
]
NSLayoutConstraint.activate(constraints)
/// UIView.h
@class NSLayoutXAxisAnchor,NSLayoutYAxisAnchor,NSLayoutDimension;
@interface UIView (UIViewLayoutConstraintCreation)
/* Constraint creation conveniences. See NSLayoutAnchor.h for details.
*/
@property(nonatomic,readonly,strong) NSLayoutXAxisAnchor *leadingAnchor API_AVAILABLE(ios(9.0));
@property(nonatomic,readonly,strong) NSLayoutXAxisAnchor *trailingAnchor API_AVAILABLE(ios(9.0));
// more anchors...
@end
""" File: nudge.py
An lldb Python script to add a nudge command.
Add to ~/.lldbinit:
command script import ~/path/to/nudge.py
Usage:
(lldb) nudge x-offset y-offset [view]
class Person {
var age: Int
init(age: Int) {
self.age = age
}
}
class Person: NSObject {
@objc dynamic var age: Int
init(age: Int) {
self.age = age
super.init()
}
}
@interface NSObject(NSKeyValueObserverRegistration)
/* Register or deregister as an observer of the value at a key path relative to the receiver.
The options determine what is included in observer notifications and when they're sent, as described above,
and the context is passed in observer notifications as described above. You should use
-removeObserver:forKeyPath:context: instead of -removeObserver:forKeyPath: whenever possible because it allows
you to more precisely specify your intent. When the same observer is registered for the same key path multiple times,
but with different context pointers each time, -removeObserver:forKeyPath: has to guess at the context pointer when
deciding what exactly to remove, and it can guess wrong.
*/
- (BOOL)shouldAutorotate {
return NO;
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
return (UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight);
}