I am using Nativescript with Angular and I would like to set the width of a Switch element.
To do this I added:
style="width: 20%; min-width: 20%;"
To the element in the template.
But the width of the element doesn't change when I test it.
Why isn't it working?
Behind the NativeScript's Switch we have android.widget.CompoundButton on Android and UISwitch on iOS. There is no option to change the width of the Switch widget but you can access the native element and modify its native width (if possible). As far as I've seen modifying the width of UISwitch is as simple as marshaling the below code to JavaScript
aSwitch.transform = CGAffineTransformMakeScale(2.0, 2.0);
In NativeScript you can access the native view (iOS or Android) via nativeView property.
For example (TypeScript):
let mySwitch= <Switch>page.getViewById("mySwith");
if (isIOS) {
let iosSwitch = mySwitch.nativeView;
iosSwitch.transform = CGAffineTransformMakeScale(2, 2);
}
Following the same principle, you could adopt a native Android solution to adjust the Android counterpart.
Related
I'm using swiftUI and I want the width and height of the screen.
It says .main will be depreciated. What should I replace it with? What's the new approach?
I have this code in my project
import SwiftUI
let width = UIScreen.main.bounds.width
let height = UIScreen.main.bounds.height
I declared this in a global file.
I'm using iOS 16.2 (the latest xcode & iOS)
My target is to create dynamic width based on screen sizes in %
How can I use screen.width property of JavaScript in SASS?
#function screen-width ($expected, $container) {
#return ($expected/$container) *100% ;
}
.demo {
width: screen-width(650px, 1000px);
}
I want the screen-width to take container width and expected width should be dynamically changed based on screen resolutions.
You can not access objects or variables from JavaScript in CSS. SASS is just a preprocessor which compiles to CSS at the build time. Thus using screen.width which is available on window object can not be accessed in your SASS code.
You can try following alternate approaches for whatever you're trying to acieve:
1) Use media queries
2) If this does solve your problem, On window.onload event, read the screen.width property and set the width programmatically using javascript.
3) If you need it the width to be set again if the window is resized, then use onresize event listener.
How do I remove the default border at the bottom of every TextField on Android using NativeScript?
The bottom border is part of the Material Design Language and cannot be removed by setting the border-bottom-width property to 0. If you do so, or try to set the color to transparent, the border will still be there. Though it may seem redundant, it can be removed by combining both properties:
TextField {
border-bottom-width: 1;
border-bottom-color: transparent;
}
More information on this here: https://github.com/NativeScript/NativeScript/issues/2626#issuecomment-261493611
I want to implement sometthing like above where the camera tab has the smaller width compare to the others tab in TabView.
I did three tabs with same size but I don't know how to add one more tab but with smaller width.
You will have to update the width of native view that contains the camera within the tab layout. The code below lets the layout take only the width it requires to show the content within.
const view = nativeTabView.getChildAt(i),
layoutParams = view.getLayoutParams();
layoutParams.weight = 0;
layoutParams.width = android.widget.LinearLayout.LayoutParams.WRAP_CONTENT;
view.setLayoutParams(layoutParams);
Playground Sample
The above example is written in NativeScript Core / TypeScript, there is nothing you have to specifically if you are implementing this on Vue / Angular, just use the appropriate event binding syntax, you should be good.
I'm targeting android but I don't know how to layout the UI so it works for all devices. How do I do this?
I have a TextField with a Button for searching and the search results are displayed below in a TableView below. So I have a table view but the bottom is cut off.
this.searchResults = Ti.UI.createTableView({
top:'70px',
height:'450dp'
});
As you can see from the code above I clearly dont know how to do this. How do you lay things out for android?
You can set top/bottom/left/right values. If you want the table to stop at the bottom edge of the screen, you could set bottom: 0. It's the same for iOS.
If I'm working on Android stuff, and I want it to resize proportionate to the size of the screen I often use percentages. So
this.searchResults = Ti.UI.createTableView({
top:'10%',
height:'90%'
});
Alternatively, If you want pin point accurate calculations, you can ask appcelerator for the platform width and height, and resize things proportionately yourself. Like so:
var height = Ti.Platform.DisplayCaps.platformHeight; //Screen height in pixels
this.searchResults = Ti.UI.createTableView({
top:'75dp',
height: (height - (75 * Ti.Platform.DisplayCaps.logicalDensityFactor)) //height - 75dp converted to pixels
});