How to make a popup window with an image SWIFT
I would simply create a reusable UIView
component and everything you need as a subview, such as a UIImageView
for your image, a UILabel
or a UIButton
in the top right. Here is the process to show it:
- Create a
UIView
that takes up the full screen, make it black, and maybe 0.5 alpha. - Create another
UIView
which is your primary pop-up view, make it slightly smaller than the previous view, but make sure both of these views are subviews of the parent subview. - Add the desired elements on to the pop-up view as subviews, I would even suggest creating a
UIView
subclass if you plan to use this a lot. - To present the pop-up, make sure both views are set to
hidden = true
when created and so that when a button is selected, you can set them tohidden = false
- If you would like them to be animated, simply start them off with
alpha = 0.0
and use something like UIView'sanimateWithDuration
and set the pop-up view toalpha = 1.0
There is a lot of little details you can change to cater to your needs, but this is the basic structure on how to accomplish your goal.
Check out UIView animation methods here.
How to create a custom pop up view with swift?
you'd create an custom UIView
with all respected object needed, from your Controller's viewDidLoad() you'll hide it.
customView.hidden = true
Whenever your user wants to perform some action or task, you unhide it and once the user finished then hide it again or remove from the superView.
customView.hidden = false
Below there is some code to help you start
private var customView: UIView!
override func viewDidLoad() {
super.viewDidLoad()
customView.hidden = true
}
private func loadCustomViewIntoController() {
let customViewFrame = CGRect(x: 0, y: 0, witdh: view.frame.width, height: view.frame.height - 200)
customView = UIView(frame: customViewFrame)
view.addSubview(customView)
customView.hidden = false
// any other objects should be tied to this view as superView
// for example adding this okayButton
let okayButtonFrame = CGRect(x: 40, y: 100, width: 50, height: 50)
let okayButton = UIButton(frame: okayButtonFrame )
// here we are adding the button its superView
customView.addSubview(okayButton)
okayButton.addTarget(self, action: #selector(self.didPressButtonFromCustomView:), forControlEvents:.TouchUpInside)
}
func didPressButtonFromCustomView(sender:UIButton) {
// do whatever you want
// make view disappears again, or remove from its superview
}
@IBAction func rateButton(sender:UIBarButtonItem) {
// this barButton is located at the top of your tableview navigation bar
// when it pressed make sure you remove any other activities that were on the screen, for example dismiss a keyboard
loadCustomViewIntoController()
}
Check it out this github project, It's closed to be production ready, it gives you a better way to deal (present and dismiss) with UIViews
If you only want the player's name then use a
UIAlertController
containing a textfield
How to open popup window contain UIview or image
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Popup Title"
message:@"This is pop up window/ Alert"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
UIImageView *tempImageView=[[UIImageView alloc]initWithFrame:CGRectMake(20,20,50,50)];
tempImageView.image=[UIImage imageNamed:@"abcd.png"];
[alert addSubview:tempImageView];
[alert show];
Popup window in swift for tutorial view
If i want a stylised popup then I will create a new Nib file and design it in there. Then when you want to show the popup you can load that NIB and animate it in, upon closing it you can animate it out.
Popupwindow with image
Create custom-dialog and pass image in it....
private void loadPhoto(ImageView imageView, int width, int height) {
ImageView tempImageView = imageView;
AlertDialog.Builder imageDialog = new AlertDialog.Builder(this);
LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.custom_fullimage_dialog,
(ViewGroup) findViewById(R.id.layout_root));
ImageView image = (ImageView) layout.findViewById(R.id.fullimage);
image.setImageDrawable(tempImageView.getDrawable());
imageDialog.setView(layout);
imageDialog.setPositiveButton(resources.getString(R.string.ok_button), new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
imageDialog.create();
imageDialog.show();
}
custom_fullimage_dialog.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_root" android:orientation="horizontal"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:padding="10dp">
<ImageView android:id="@+id/fullimage" android:layout_width="fill_parent"
android:layout_height="fill_parent">
</ImageView>
<TextView android:id="@+id/custom_fullimage_placename"
android:layout_width="wrap_content" android:layout_height="fill_parent"
android:textColor="#FFF">
</TextView>
</LinearLayout>
Related Topics
Where to Find a Clear Explanation About Swift Alert (Uialertcontroller)
How to Automatically Create an Initializer for a Swift Class
How to Retrieve Image Stored in Firebase to Show It in View Image View
Changing Selectedimage on Uitabbaritem in Swift
User Notification Request Always Come with Default Action Identifier
How to Create a Custom iOS Keyboard
How to Delete an Image from Photolibrary After I Pick It Up Using Uiimagepickercontroller
How to Send Different Users to Separate View Controllers Using Firebase and Xcode
Apple Healthkit - Background Updates Not Triggering
Avcapturestillimageoutput VS Avcapturephotooutput in Swift 3
How to Determine If a Business Is Open Given the Hours of Operation (Swift-Ios)
How to Send Msmessage in Messages Extension
Using Haneke to Cache Then Play Mp4 Files with Avplayer
iOS Keyboard Active But Invisible When Uisearchbar Is Tapped