Sunday, 14 April 2024

iOS Apps & Objective-C: Using the IOSCustomAlertView!

 This time we're gonna be going over yet again another very interesting thing however this is much different than within my other tutorial in one way if you are arson RS subscribe to subscribe to my channel and you have watched most of my videos you know that I like to focus on Swift iOS NASA and Mac apps well today I'm changing it up not by switching the iOS platform mice but by switching the actual language so today I'm gonna be doing a video on objective-c instead so apparently this is going to be my first objective-c video I even though it should be very old I mean even though objective-c Rosalie's before Swift I actually started making videos after Swift was released because I found a bit easier however someone called Amrit you must have already heard him another link to a video that he suggested will be down in the description and you can check that out and so he also suggested this one to me however his requirement was to have it written in Objective C completely 100% you can't even use a little bit of Swift so I used as you can see Richards API to do this now first let's explain the app before I get into the API this app allows you to use custom alert views or I'm not exactly sure I think in iOS 8 now they call them alert controllers however I just called them used for some for some reason however view still works there just deprecated anyway so as you can see this app allow these custom alert views but what does that mean let me give you an example as you can he see here I've given you a little example because over here we have a little window and so this is going to be our alert view it'll have three buttons on it or at least that's our requirement you can have it one button to button three buttons or even four buttons or even five you can put as many buttons as you want here as long as their text will fit and then I'm going to have a little image in this alert view so that we can actually use what this is for it's because I you can put images in native iOS alert views however it is much harder so I just use Richards API in where to help us to do that so yeah that was really it there's no algorithms to explain there's no main flowchart to make so let's get straight into the my part I'll see you there so welcome back to the Mac part of the video and this is gonna be a considerably shorter video than the rest of my videos they usually are but I know y'all gonna like it because I haven't really found much documentation for this API which I will be giving you right now so let's continue as you can see now I'm gonna give you a demo of this app this means new simulator running we have a pretty blank screen but we also have a button here called show the alert I wonder what's could do well she was a picture of my face apparently and it also has three buttons okay bye and cancel so all of these three buttons do the same thing and so they weren't really programmed to do much but they all work they close the alert view for us and so again is anything Richards API as you can see hers name here he created this in 2013 so yeah he's linked for this source code will be down in the description and it's only two files in Swift it would have been one file because there's the header and the implementation however I'm not really going to argue about that right now anyway we have our app delegate like always even and swift we do and then we have our own header and implementation files and as you can see in my header I am actually declaring the show alerts IB action Here I am defining our short Show alert IB action okay so in this show all or IB action this is what's linked to our show the alert button this will create a new alert which is of type custom iOS alert view which is an implementation of Richards API and then we are creating an image view which is a just a fresh image view we're creating a new variable called rect which is a cg rekt which is equal to the image views frame we are setting the rect heist hi sorry to 232 we're sending its width to 242 we're setting the image views frame to a new rectangle that we've modified we are setting the images image to myself which I saw it in the XPS assets file over here then back here we are sending the images content mode to UI view content mode Center we are setting the container view for the alert to this image view so that we can show the image view on the alert and then we are setting the alerts buttons titles to okay bye cancel and now then we are finally showing the alert view which is very simple you just do alert show you can see that was a pretty short video but that was really it I hope you guys all liked it if you have any questions or if you have any suggestions for future videos or even anything on this if you'd like me to modify this at all you can just leave it down in the comment section below you can even email me at a g-man e at gmail.com my email will also be down in the description if you didn't get that and yeah you can also subscribe to my channel if you like my content you want to see more of it and please like the video if you liked it and that will be all good bye

No comments:

Post a Comment

Connect broadband