有没有办法在代码
问题描述:
中创建一个UIView的框架(在故事板中创建)我在故事板中创建了一个UIView
,并且想要为该视图添加一些内部阴影。我也为此创建了一个IBoutlet
。有什么方法可以获得视图的框架?有没有办法在代码
@IBOutlet weak var display: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
print(display.frame.height)
}
错误
Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<Calculator.ViewController 0x7fba77608cd0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key screen.'
*** First throw call stack:
(
0 CoreFoundation 0x000000010d7a2b0b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x0000000109cd5141 objc_exception_throw + 48
2 CoreFoundation 0x000000010d7a2a59 -[NSException raise] + 9
3 Foundation 0x00000001097eb00b -[NSObject(NSKeyValueCoding) setValue:forKey:] + 292
4 UIKit 0x000000010b09e994 -[UIViewController setValue:forKey:] + 87
5 UIKit 0x000000010b30ba09 -[UIRuntimeOutletConnection connect] + 109
6 CoreFoundation 0x000000010d748e8d -[NSArray makeObjectsPerformSelector:] + 269
7 UIKit 0x000000010b30a3bf -[UINib instantiateWithOwner:options:] + 1856
8 UIKit 0x000000010b0a4fc3 -[UIViewController _loadViewFromNibNamed:bundle:] + 381
9 UIKit 0x000000010b0a58d9 -[UIViewController loadView] + 177
10 UIKit 0x000000010b0a5c0a -[UIViewController loadViewIfRequired] + 195
11 UIKit 0x000000010b0a645a -[UIViewController view] + 27
12 UIKit 0x000000010af6e98a -[UIWindow addRootViewControllerViewIfPossible] + 65
13 UIKit 0x000000010af6f070 -[UIWindow _setHidden:forced:] + 294
14 UIKit 0x000000010af81ebe -[UIWindow makeKeyAndVisible] + 42
15 UIKit 0x000000010aefb37f -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4346
16 UIKit 0x000000010af015e4 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1709
17 UIKit 0x000000010aefe7f3 -[UIApplication workspaceDidEndTransaction:] + 182
18 FrontBoardServices 0x0000000111b715f6 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 24
19 FrontBoardServices 0x0000000111b7146d -[FBSSerialQueue _performNext] + 186
20 FrontBoardServices 0x0000000111b717f6 -[FBSSerialQueue _performNextFromRunLoopSource] + 45
21 CoreFoundation 0x000000010d748c01 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
22 CoreFoundation 0x000000010d72e0cf __CFRunLoopDoSources0 + 527
23 CoreFoundation 0x000000010d72d5ff __CFRunLoopRun + 911
24 CoreFoundation 0x000000010d72d016 CFRunLoopRunSpecific + 406
25 UIKit 0x000000010aefd08f -[UIApplication _run] + 468
26 UIKit 0x000000010af03134 UIApplicationMain + 159
27 Calculator 0x00000001096fa327 main + 55
28 libdyld.dylib 0x000000010e74265d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
帮助表示赞赏
display.superview?.frame – Pushpendra
也还是让我知道什么是您的打印(display.frame)打印.. – Ishika