In Xamarin.Forms I change FontFamily from myButton. Now I want to set default FontFamily to it. Now I use myButton.FontFamily = (new Button()).FontFamily. Is there a more appropriate way to do this?
you can reset the value to it's Default:
myButton.ClearValue(Button.FontFamilyProperty);
Related
Looking for the code-behind equivilant of FontFamily={StaticResource FontAwesomeBrands}.
I've tried setting it directly to that string and was not too suprised when that didn't work. If I use that FontFamily in the XAML it works fine, just not sure how to do this from the code-behind.
You can call any resource from the Resources file just with the resource name.
var OnPlatformDic = (OnPlatform<string>) App.Current.Resources["FontAwesomeBrands"];
var fontFamily = OnPlatformDic.Platforms.FirstOrDefault((arg) => arg.Platform.FirstOrDefault() == Device.RuntimePlatform).Value;
YourLabel.FontFamily = fontFamily.ToString();
In previous iOS versions, I was able to change the text and background colors using the something like the following:
let datePicker = UIDatePicker()
datePicker.datePickerMode = UIDatePickerMode.date
datePicker.setValue(UIColor.white, forKey: "textColor")
datePicker.backgroundColor = UIColor.black.withAlphaComponent(0.6)
This is no longer working in Xcode 10/iOS 12. The date picker is displayed with its default colors. Has anyone found a solution for customizing the text and background colors in iOS 12?
It seems something is resetting those values between when I set them and when the view is displayed. I was able to solve this by subclassing UIDatePicker and setting the values in layoutSubviews(). There may be a more performant place to set the colors, but this is working for me for now.
class DatePicker: UIDatePicker {
override func layoutSubviews() {
super.layoutSubviews()
backgroundColor = UIColor.black.withAlphaComponent(0.6)
setValue(false, forKey: "highlightsToday")
setValue(UIColor.white, forKey: "textColor")
}
}
I have an extension for UIColor to get color from hex string. I'm using it as per below:
self.navigationItem.rightBarButtonItem?.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor(hexString: "#C0BFC0")], for: UIControlState.disabled)
self.navigationItem.rightBarButtonItem?.isEnabled = false
For some strange reason the color of the rightBarButtonItem is the same as before. Is there a way to change it when disabled? I have the above in my viewDidLoad function
I tried reading the below:
UIBarButtonItem is disabled, but has normal color
Change color of disabled bar button item in iOS
I'm able to change the color when it is not disabled. Seems when its disabled the colors are not obeyed?
when its disabled the colors are not obeyed?
I hit this bug with some toolbar items. My workaround is to ensure that the UIBarButtonItem title changes at runtime, when the disabled color should change. To do this, change the disabled color, then force the title to change by adding an invisble Unicode space if needed.
For example in Swift:
let zeroWidthSpaceStr = "\u{200B}"
func forceChangeItemTitle(_ item:UIBarButtonItem, newTitle:String) {
// Ensure the button item title is changed. Needed to pick up change in disabled text color
var newTitle = newTitle
if item.title == newTitle {
// Title already set, so change it invisibly
newTitle += zeroWidthSpaceStr
}
item.title = newTitle
}
I created a basic NSTextView, I selected the following options in Interface Builder:
Editable
Selectable
Field Editor
Rich Text
Undo
Graphics
Non-contiguous Layout
Font Panel
Ruler
Inspector Bar
I set the NSViewController to be the delegate of the NSTextView and the only other custom thing I've done for this NSTextView is to enable inserting tabs and new lines (by accepting First responder):
func textView(_ textView: NSTextView, doCommandBy commandSelector: Selector) -> Bool {
if commandSelector == #selector(insertNewline(_:)) {
textView.insertNewlineIgnoringFieldEditor(self)
return true
} else if commandSelector == #selector(insertTab(_:)) {
textView.insertTabIgnoringFieldEditor(self)
return true
} //else if commandSelector == #selector(changeColor(_:)) {
//textView.setTextColor(NSFontPanel.colo, range: <#T##NSRange#>)
//}
return false
}
When I try to use the commands from the Font Panel + Inspector Bar, All the commands work fine except changing Font size or colour, is there anything that could be wrong? Or do I need to do extra binding/delegates, etc for this to work?
It is strange because if I change the Font itself (of a selected text) or the weight, it works fine (no coding was needed).
Update
I've found the root of the problem causing this. I'm displaying the TextView in a ViewController that is displayed using a Modal segue. If I change from Modal to Show, the size and colour work fine. There's also no need for the extra commands for insert new line and tab.
Is there any reason why this is the case? Is there any customisation that should be done to the segue to avoid this? And, why is the view controller presentation affecting the behaviour of the font panel?
NSFontPanel has a 'worksWhenModal' property which sounds as if it might be set to 'false'.
A Boolean that indicates whether the receiver allows fonts to be changed in modal windows and panels.
Documentation:
There is a new property of UIView: layoutMargin in iOS8.
In order to set the margins of a view programmatically:
self.view.layoutMargins = UIEdgeInsetsMake(0, 0, 10, 10);
Is it possible to set margins in Interface Builder?
This can be achieved by setting a User Defined Runtime Attribute in the Identity Inspector:
Although Xcode does have a margins setting, as of 7.3 (7D175), it still doesn't have any effect, so you have to use the user defined attribute: