How to remove top bar from Xamarin.Forms (iOS)? - c#

How can I remove the top bar from iOS project of Xamarin.Forms? Where the time and "Carrier" word are
.. or at least measure its height?
Just to be sure.. I don't want to see battery, time... I want to hide the bar in the red rectangle:

You can add this code on your AppDelegate.cs inside FinishedLaunching method after LoadApplication (new App ()); on iOS Project:
UIApplication.SharedApplication.StatusBarHidden = true;
also add this on your info.plist:
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>

Go to Info.plist file in your iOS project
Click Source and Hover on one of those lines and a (+) and (-) button will show up. Click the plus button to add new key
Type in start with capital V and automatically the first choice will be View controller-based status bar appearance. Add that as the KEY.
Set the VALUE to "No"
Now you can still see the time alone
Then Click again the plus button to add new key
Now choose Status bar is initially hidden and add key "Yes"
In case of you want to hide programatically for each page. You have to create custom renderer for each Forms Page with UIViewController.
In UIViewController, you can override method like below
public partial class CustomViewController : UIViewController
{
public override bool PrefersStatusBarHidden()
{
return true;
}
}

Goto info.plist
Just check the HideStatusBar

Related

How to remove black outlines on buttons after clicking on form in windows forms

i am making a flat GUI in windows forms.. i know i cant just ignore and leave tab indexing and i have included it. when i am using tab in my program to select control,a black outline appears on controls(as in this pic). what i want is to remove this outlining when i mouse-click anywhere because it seems Ugly if i am not using my keyboard.
how can i remove this outline on flat button
can you suggest me how can i achieve this target?
Try hiding the focus cue by creating your own button:
public class ButtonEx : Button {
protected override bool ShowFocusCues {
get {
return false;
}
}
}

Remove tinting from iOS TabBar

I have a TabBar at the bottom of my view that I dont want any tinting on. As od iOS 7, iOS automatically tints the icons blue and I dont want this to happen.
I have tried writing a custom renderer but setting the tint colour to clear simply removes the icon (should have seen that one coming).
protected override void OnElementChanged(VisualElementChangedEventArgs e)
{
base.OnElementChanged(e);
TabBar.TintColor = UIKit.UIColor.Clear;
}
I want to have an image for the tab item without any tinting. How can this be done?
If anyone still looking for solution, you can go to your image assets, select all your tab icons (including Selected style), and in its options choose Render As: Original Image instead of Default.
No additional action is required, you can select any tint color in your TabView (or Image View) but it will not affect it any way. Also you can do it programmatically, but this is bit more simpler.
Although I am not sure since which iOS this function is available, it might be helpful to others with similar issue.
A bit late but I had a similar problem, here's what I did. I created a custom tab bar and set the tab bar item to use the original image (without tint). Then, I specified to use the rendering template when the icon is selected.
public partial class UICustomTabBar : UITabBar
{
public UICustomTabBar (IntPtr handle) : base (handle)
{
//Set your colors
BackgroundColor = UIColor.White;
SelectedImageTintColor = UIColor.Red;
foreach (UITabBarItem tabBarItem in Items)
{
tabBarItem.SelectedImage = tabBarItem.SelectedImage.ImageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate);
tabBarItem.Image = tabBarItem.Image.ImageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal);
}
}
}
If you want to use original icons to show on tab bar and without using selected or unselected tint color which applies by default.
Then we have to use custom renderer for iOS and for Android we have to use vectors
For detailed information you check the below link
https://www.davidbritch.com/2020/11/display-svgs-as-tabbedpage-tab-icons-in.html
You cannot.
Tab bar buttons don't display colors. Tab bar buttons use only the alpha information from the images you assign to them. You can use a segmented control instead.

Docking an existing QWidget in QWindow

For those who are very familiar with C# or VB.NET using the UserControl component in the .NET Framework (which is the hottest framework in my opinion), you were used to adding several buttons that preview different user controls as follows:
1) First you would prepare an appropriate user interface (contains 3 buttons and a single panel on the right area to view each user control after clicking one of the added buttons).
2) Adding 3 user controls from the solution explorer...
3) Inserting the content on each user control...
4) Implementing code for the 3 buttons on the frmMain.cs as the following (for this implementation we will be implementing the "Welcome" button carrying the object name as welcomeBtn, and the rest will have identical code but different user control names instead):
private void welcomeBtn_Click(object sender, EventArgs e)
{
//Clear up everything from the panel if any item exist(s)...
mainPanel.Controls.Clear();
//Create a new instance of a user control for the button...
UserControl1_Welcome welcome = new UserControl1_Welcome();
//Show up the created instance of the user control
mainPanel.Controls.Add(welcome);
}
5) Finally, the program will end up initially like this when running:
http://i.stack.imgur.com/OENwG.png
** Usage of the program **
When you click on the "Welcome" button for example, the result should be expected to be like this:
http://i.stack.imgur.com/iCyo3.png
... and when you click on a different button, lets say "License Agreement" button, you would expect to see something other than your current selection.
MAIN QUESTION
How can we bring the simplicity of Windows Forms in QT CREATOR by applying the "QDockWidget"?
I have tried inserting the QDockWidget component with no problems, but when I try to do the equivalent .NET code for adding the QWidget inside the QDockWidget:
ui->dockWidget->setWidget(myWidget);
which I think is equivalent to this line of code in C#.NET (correct me if I'm wrong here):
ui.Controls.Add(myWidget);
After using this code, my program won't crash nor shows anything running...
P.S. I'm sorry for linking the images, I don't have 10 reputation for making them show up...
What I want is to have a program that does the same thing with the C# example (showing a user control based on the click of a button).
If you want to show a particular widget based on a button click, I suggest to use a QStackedWidget
A simple example would be like this:
// In the constructor of your CustomWidget
// Create your buttons
QPushButton* firstButton = new QPushButton("First Button", this);
QPushButton* secondButton = new QPushButton("Second Button", this);
QPushButton* thirdButton = new QPushButton("Third Button", this);
// Create your (custom) widgets
QLabel* firstPageWidget = new QLabel("First Label", this);
QLabel* secondPageWidget = new QLabel("Second Label", this);
QLabel* thirdPageWidget = new QLabel("Third Label", this);
// Add them to the stackWidget
/*QStackedWidget* */ m_stackedWidget = new QStackedWidget(this);
m_stackedWidget->addWidget(firstPageWidget);
m_stackedWidget->addWidget(secondPageWidget);
m_stackedWidget->addWidget(thirdPageWidget);
// Insert buttons and stackWidget to CustomWidget
QVBoxLayout* layoutStack = new QVBoxLayout();
layoutStack->addWidget(m_stackedWidget);
QVBoxLayout* layoutButtons = new QVBoxLayout();
layoutButtons->addWidget(firstButton);
layoutButtons->addWidget(secondButton);
layoutButtons->addWidget(thirdButton);
QHBoxLayout* layout = new QHBoxLayout();
layout->addLayout(layoutButtons);
layout->addLayout(layoutStack);
setLayout(layout);
// Connect button clicks to slots
connect(firstButton, SIGNAL(clicked()), this, SLOT(onFirstButtonClicked()));
connect(secondButton, SIGNAL(clicked()), this, SLOT(onSecondButtonClicked()));
connect(thirdButton, SIGNAL(clicked()), this, SLOT(onThirdButtonClicked()));
Then you change the currently visible widget in the slots:
void CustomWidget::onFirstButtonClicked() {
m_stackedWidget->setCurrentIndex(0);
}
void CustomWidget::onSecondButtonClicked() {
m_stackedWidget->setCurrentIndex(1);
}
void CustomWidget::onThirdButtonClicked() {
m_stackedWidget->setCurrentIndex(2);
}
Note that if you want the button clicks just to simply change some text (as opposed to change the visible widget), you probably better use a QTextEdit instead of a QStackedWidget, and in the slots call setText("....");
If you have a lot of buttons, you'd better use QSignalMapper to limit the number of slots.
Also, I didn't get why you mentioned QDockWidget since they have a quite specific usage:
The QDockWidget class provides a widget that can be docked inside a QMainWindow or floated as a top-level window on the desktop.
QDockWidget provides the concept of dock widgets, also know as tool palettes or utility windows. Dock windows are secondary windows placed in the dock widget area around the central widget in a QMainWindow.
If you simply want a separate window, you're probably looking for a QDialog
How to do this with QtDesigner:
First you would prepare an appropriate user interface (contains 3 buttons and a single QStackedWidget on the right area to view each user control after clicking one of the added buttons).
Adding 3 pages for the user controls in the stack (+ one for the "empty" page if you really need that). If you want to design the Controls in separate UI Files / Only in Code (instead of all controls in your MainFrame), you would add plain QWidgets and promote them to the appropriate specific widget type
Inserting the content on each user control...
Implementing code for the 3 buttons on the frmMain.cpp/.h as the following (for this implementation we will be implementing the "Welcome" button carrying the object name as welcomeBtn, and the rest will have identical code but different user control names instead):
void FrmMain::on_welcomeBtn_clicked() {
ui->stack->setCurrentWidget(ui->welcomeWidget);
}
Select the "empty" page at as the current page in the designer, so the program will end up initially like this when running: (your screenshot)
When you click on the "Welcome" button for example, the result should be expected to be like this: (your second screenshot)
In my opinion, Miki's answer is the only correct approach to this use case (using a QStackedWidget).
For sake of completeness, I'll demonstrate how the same Clear and Add method as used in .NET is done in Qt:
// Assume controlPanel is a QWidget where you want to place the items
// Assume that controlPanel has set a layout (e.g. QHBoxLayout)
// Clear: Remove all Items from layout
QLayoutItem *child;
while ((child = controlPanel->layout()->takeAt(0)) != NULL) {
delete child;
}
// Now widgets are still there, but not layouted. Delete them explicitly
foreach (QWidget * w, controlPanel->findChildren<QWidget*>()) {
w->deleteLater();
}
// Now controlPanel is cleared
// Add new control
controlPanel->layout()->addWidget(new MyNewControlWidget);
First is, we can not force how other framework works to another one. Each framework has its flow and design.
What I am understand is you want to show another widget to the main window.
If you want to use the QDockWidget, its says on the documentation like this :
void QDockWidget::setWidget(QWidget * widget)
Sets the widget for the dock widget to widget.
If the dock widget is visible when widget is added, you must show() it explicitly.
Note that you must add the layout of the widget before you call this function; if not, the widget will not be visible.
Please share here you code of myWidget, so we can try to help you to figure out what is wrong.
On my side, I can achieve it by add the QVboxLayout on your ui->dockwidget and add QLabel with emtpy string and when you want to show myWidget just call ui->dockwidget->vboxlayout->replaceWidget(label, myWidget);

NullReferenceException Error When Trying to Change the Property IsEnabled of an AppBar Item

On one of my .xaml pages, I have an appbar with a few icons on it.
One of the icons pins the page to Start, so when it is pinned I want to change the IsEnabled property of that icon to false.
However I get this weird error; as described in the title when this procedure is called.
Here's the code:
if (Tile == null) { }
else { appBarPin.IsEnabled = false; }
any ideas?
The behavior with the Application Bar is different to the rest of UI elements. From App bar for Windows Phone:
The app bar doesn’t support some common features of controls, such as
data-binding. As a result, you can’t change the icon button and menu
item text by using Name properties that you set in XAML.
If you want to change a property of the appbar item, do it the following way:
ApplicationBarIconButton button = (ApplicationBarIconButton)ApplicationBar.Buttons[0];
button.IsEnabbled = false;
Replace the 0 with the index of the button. I.e. if the button is the second button of the appbar, the index will be 1.
See more in How to change app bar icon buttons and menu items dynamically for Windows Phone
A null reference exception means that you can't say ".IsEnabled" if the thing before the dot is null.
It appears that appBarPin is null.

Numeric keypad on MonoTouch

I have a problem when using MonoTouch.Dialog to create a login screen.
If you look at the screenshots below, for a user to login they must enter their mobile number and PIN. Both of these EntryElements use a numeric keypad. The first problem is that there is no way to move from the mobile number field to the pin field. Secondly once they have entered their pin there is no 'done' button or anything to dismiss the keyboard. It's very counter-intuitive for them to scroll up in order to poke the Login button (shown in the second screenshot).
How do I get the little bar with previous, next and done buttons as shown in the third screenshot? I've seen this on some apps and was wondering if it's possible to get this working using MonoTouch.Dialog?
Keyboard in the way:
How do you dismiss the keyboard?
Ideally this is what I want:
This other Stackoverflow answer shows how to add a "done" button on top of the keyboard. Using this method you can add other buttons, as well.
The answer is to create your own DialogViewController with the following:
private UIView _toolbar;
public override UIView InputAccessoryView
{
get
{
return _toolbar;
}
}
You then create whatever you want to display in the UIView that is returned. I used a UISegmentedControl for the Next and Prev buttons and a UIBarButtonItem for the Done button.

Categories

Resources