I've got a problem in my ContentView:
I want to bind my BackroundColorto a Grid and a StackLayout
BackgroundColor="{x:Static local:Const.Color_BackgroundNavigationBar}"
This works very well in my ContentPage, but in my ContentView i got an error:
Position 25:108. No property, bindable property, or event found for 'BackgroundColor'
The namespace for local is the same as in my ContentPage.
Is this a Problem which exists because of the ContentView or something else?
The error basically says it all; a ContentView does not have a property BackgroundColor. See the documentation page for this type.
Ok I found the solution myself:
The ContentView was a Child of my ContentPage so I needed to set the Binding with the Source extra:
BackgroundColor="{Binding Source={x:Static const:Const.Color_BackgroundNavigationBar}}"
Hope I interpreted the solution correct, now it is working.
Related
After searching online I found that, if we declare a property inside a custom view as #IBInspectable, that property can be altered in the IB attribute inspector.
But my question is what is the use of #IBDesignable. Even if I don't declare a class as # IBDesignable, Im able to see the live rendering of the #IBInspectable properties
IBDesignable is user defined run time. Mean that if any IBDesignable view is rendered on the storyboard, you will find the view and change the value of the IBInspectable property, this will directly reflect on the storyboard without running the app.
IBInspectable is run time property, this works as key coding value. You can't find the change in storyboard, it will be applied in the run time.
The live rendering of a custom view should stop once you remove #IBDesignable. But sometimes this does not happen immediately.
If you remove #IBDesignable, then, close and reopen Xcode.
You should not see any live rendering the custom view directly in the canvas.
I have looked at the answers of this question here and none of them seem to fix the problem I am having, also most other answers are not for swift but i tried the ones I understood.
All of the class names match, the outlets have the right names and there are no outlets that aren't defined... no little yellow triangle. (links to images below, site wont let me put more than 2)
Shows class names in inspector and file are the same
Shows outlet names in file and inspector
As the screenshot clearly shows, the property MyInputText does not bind to anything. Did you connect the UITextField in the UIStoryBoard to the related property in the code?
Here a screenshot showing a proper binding between a property and the XIB object.
Here a screenshot showing a proper binding between a property and the XIB object.
I found a view is somehow added under the control of a view controller, how can I track this process while debugging? My goal is to find where and how this view is created and added so that I could remove it since I don't need this view. Thanks.
You can use the Debug View Hierarchy:
Here you can see al the views, find the one you' re looking for, select it and select Show the Object Inspector:
There you will see the memory address of the object, in my case I've selected a UILabel, then you can add a watch expression on the debug area by right clicking:
Write the address casted to your view element (again, in my case a UILabel):
((UILabel*) 0x14ff9c80)
Finally, you will see something like this:
With this you will be able to get some information of the view you're looking for.
You can create a custom subclass for your self.view in UIViewController and override addSubview and insertSubview:atIndex and put breakpoints there.
All added views then should trigger a breakpoint.
I have created a custom view (Quantity View) with nib file in Swift. I have created some IBOutlets & IBActions (for buttons, labels etc.) in my custom view.
I tried to use this custom view (Quantity View) by assigning class name to a UIView in my storyboard.
It's showing me all the IBOutlets & IBActions in the Connections Inspector, as shown in this screenshot: .
I just want to show only delegate for the Custom view.
Possible Answer:
I thought I can use the -viewWithTag to get the views instead of Outlets.
But, I want to know if it's possible with having Outlets also or if there is much better way to do this?
What are the other possible ways (optimum) to handle this situation?
You can also consider the following solution:
You can take the subviews of your QuantityViews(custom view) and you can identify the specific views by its frame origin.
Note : you should know the customview subviews frame
Its not possible to hide IBOutlets from storyboard if you declare the class members as IBs (IBOutlets or IBActions).
The IBOutlets or the IBActions are just indicators to the interface builder so that it can show the names on it when you try to bind them it actually calls the setValue: forKey: method to set the view's reference to the IBOutlet property.
Now if you try to access an subview from the file's owner class without any IBoutlets you need to have a pointer to point it, so for that either you can get the reference using ObjectID which is assigned to the subview by the interface builder or you can get it using the viewWithTag: method.
The ObjectID you need to find all time when you add or replace a subview from the view, so better and convenient approach is to use tag property of UIView class.
So my conclusion to this problem is to access the views using the viewWithTag method you mentioned earlier.
I think your way is correct. But sometimes Xcode doesn't work correctly.
The following makes the IBOutlets and IBActions reappear and work properly:
Clean project your project in Xcode.
Quit Xcode completely.
Delete all contents of ~/Library/Developer/Xcode/DerivedData/.
Restart MacOS just in case.
I hope you will resolve that :)
Apple's UIAccesibility Protocol reference states:
UIAccessibilityLabel
Discussion
The default value for this property is nil unless the receiver is a UIKit control, in which case the value is a label derived from the control’s title.
Well... both UIView and UIViewController are in the UIKit framework, but I can't find the default accessibility label for my view who's controlled by the UIViewController named LoginVC. I tried to log it, but get a blank string. Is that right? is the doc wrong? Or am I doing something wrong?
I know I can set the accessibility label manually; I'd like to avoid the clutter and use defaults if possible - which are already generally descriptive if their name is actually derived from their controller.
By default, a UIView and a UIViewController have nothing set for their title property, so the default accessibilityLabel property (which is derived from the title property) correctly and expectedly returns nil. Set their title properties (either in code or in Interface Builder) and you'll see it when you log accessibilityLabel at runtime.
I don't think Accessibility will populate itself automatically, if that's what you're asking.
If you asking for ways to set it, you should be able to do it programmatically:
[myButton setAccessibilityLabel:#"Hello"];
If you use Interface Builder, there is a field in the Identity Inspector tab that will allow you to set this. Select your view under Objects on the left. Then click the third tab from the left for Identity Inspector. Example below: