Posts

Showing posts from 2019

Solution Force Close When Save Image in UIActivityViewController Swift 5 iOS 13

Image
Hello guys, It's last week for this year. And it feels so fast for me. I have started to be more consistent on this year. I started to post once every week, it's not hard for people have much time. But for me to think about what's next article need more time. I have to have a problem to make a solution haha. Tommorow will be on first day of 2020 year. It's nice to know 2019. And good bye 2019 haha. So now the problem I faced when I was trying to save image through UIActivityViewController. After saving image the current view controller will dismiss. And it's a bug from iOS, it's confirmed on the internet stackoverflow that I give link on below. Many people faced it before me haha, thanks I know it late so that I don't need to figure it be myself haha. I hope this bug will soon be fixed by Apple. How can this bug didn't happened on iOS 12 but happed on iOS 13. I think it's because iOS 13 introduced new feature modal presentation. We need t

Missing system image Android Studio solution

Image
Happy holidays guys, this is december with long weekend haha. I still have a problem with Android Studio. After I update my emulator and suddenly I got a issue that is so weird. You can see picture above I need to redownload emulator from android studio. If you got a issue like me, don't worry and don't uninstall your android studio. It's not complicated to resolve it. You just need to redownload the emulator go to Tools -> AVD Manager. You can see the issue of your emulator and redownload or resolve it. And you will be like image above. Just wait the download and your emulator will be fine again. If you still have the issue, please comment below and let me know what's the problem. I'm happy if i can help you guys. I'm not expert but it's fun when i can solve programming issues.

How to have ConstraintLayout inside ScrollView and ScrollView inside ConstraintLayout Android

Image
Hai guys, last week I found a unique way to create layout Android look. You can see the title, that's actually what I want. I know it sounds weird but sometimes we need to create something that we might curious if it's in o n the internet or not. Why I'm using ConstraintLayout because it's almost same with iOS xcode. There is constraint where you can set top constraint, bottom constraint, left constraint and right constraint. So it's easy for me to design like what I want. But it's personal, it depends on you too. And fortunely you can combine ScrollView and ConstraintLayout. Because you need to worry when the height of your layout is high than real device height. And if you don't use UIScrollview your component will be unseen when the height of device is more small than layout that we design. Like my app, I want to use ConstraintLayout and ScrollView together. Maybe it can do with RelativeLayout or others layout. But something special that I want i

How to add back arrow in AppCompatActivity Android

Image
Hello guys, welcome back it's monday today but I'm not gonna post this day maybe tommorow. Today I don't give article about iOS but Android. Because Android has many users so it's not bad to learn it. Basically it's same logic but just different how to implement the layout and components. Android is using java but you can use kotlin but this article I just show Java code. Because I'm too lazy to convert it hehe. In this article I wanna talk about activity and navigation when you want to go back previous activity and you need to do it through toolbar. I have found easy way to implement it. It's a few codes line, no need to import icon and libraries. It's included in Android Studio library. I have tried it like screenshoot above and it works when you extend AppCompatActivity. It will automatically give you a back arrow icon in action bar. No more code needed. It's awesome right, android make it simple. I haven't tried to override the back

Better Using setNavigationBarHidden than zPosition to hide navigation bar

Image
Hello all, This is my first post in December. It's good we reach final month of the year. And I haven't forgot to post article again every week. I'm stil consistent though. This day I'm talking about navigation in iOS. It's very important to have navigation in iOS because every apple apps using navigation too. Sometimes we need to customize our navigation as we want. And we need to do our own. Because apple doesn't have full feature to edit like UIView did. So we need to create UIView and make it like navigation. It's ok to use UIView than navigation because it looks same and doesn't have bad impact for our app. And you can custome as you want and it will make your app different from other in good way. Remember too you can avoid using navigation with present and not include navigation controller. But the advantage to use navigation you have feature swipe to back to previous controller. And it has a animation left to right or right to left. Altho

Different Bounds between UIScreen.main.bounds and Self.view.bounds

Image
As you know guys, sometimes we want to get height of the screen or the width of the screen. And It's different for every devices. But it's surprisingly different if you call it in ViewDidLayout and ViewDidApper. Why it can be different ? because in ViewDidLayout the view is not loaded in device screen. And it's bad to get height or width from there. But if you call UIScreen.main.bounds, it will return the right size because UIScreen no need to wait in ViewDidAppear like self.view.bounds. The user will see some things, it's not good. Like the height change but it's not animation but the bug of waiting the right width. And I encounter that problem, it needs a solution. But my solution before it's not good. Because I just show when the user have arrived and it looks like there's delay displaying the view. So the solution is initialize the view in ViewDidLayout but using UIScreen.main.bounds to get the right bounds and not self.view.bounds. Self.view.bo

Fixing Keyboard Hide When Reload UITableview iOS swift 5

Image
Hello guys, If you ever worked with UITableview and UITextView or UITextfield. Like chat App or Comment app. You will face the keyboard will hide or in other word the keyboard close to down. And If we other famous apps like Instagram, it's not close but still exist even if we type and send messages. And In this article I want to share with you guys, how to avoid it so you can easily make the keyboard always opened guys. I found many solution on the internet but some are bad because the keyboard have animation close and open again. I used UITextview and customize it using GrowingTextView. Because I want to the Textbox change the height when user make a new line. So it will look like Whatsapp chat and It looks good. And I make the textbox above keyboard so it will make the user easily type and send messages. The point is to make a new class custom and override canResignFirstResponder variable. So we can change it in our own class view controller. And that's good becaus

Avoid Wrong Height UITableView When Reload and Add New Row

Image
I have a problem where I can't find the solution on the internet like google, stackoverflow and blogs. So I need to trick this so that It work like I want. It's like the bug from iOS because what's supposed to be i'm doing it's the correct way. And the error seems weird because it's only sometimes happened. I try to find it by way and it takes long time. And finally I got the solution but I think it's not final solution but I hope iOS will fix the issue soon. So the error it's when you first time entering UITableview.  If you dynamic height like instagram did, you will sometimes get wrong height. But if it's not you are saved. I don't know if this problem only happened to me or not but after a few years expierence. I think this bug happened not only me. My solution is not the best but I think it's really good to hide the pain because of this annoying bug haha. What I did is to refresh three times refresh when first reload UITableview.

Add Loading ActivityIndicator in AVPlayer Video iOS Swift 5

Image
This week, I want to show loading after I have a video player that uses AVPlayer library. If you're curious like me. Stay tuned in this blog or if you're in hurry just scrolling on bottom. I must've given the source code. If you're an expert it must be easy to follow. So if you don't use playback controller library AVPlayerViewController. I mean maybe you use AVPlayer Layer. It's basically it doesn't have playback controls. It's good to use loading Activity Indicator so the user will have a good expierence to operate our app. So basically the AVplayer itself has a loading indicator beside play/pause button as you can see on above image. But it's not enough for me because it's too little, I need something on center like I do in UIImageview or loading something like loading API. And the problem with AVPlayer, it doesn't have delegation to perform loading action so we need to use observer to do it. And don't forget to add the Activ

How to get thumbnail from video URL in Swift 5

Image
If you want to show video in your app and you want to show thumbnail. The easy way is to get image url from server API. But there is more easy way you just need to get url video and get image url. I have searched on the internet but what I found my app becomes lag. I use UITableview to show the video thumbnail url. Maybe you wonder why I use image thumbnail. I can use video player from iOS and thumbnail video will be shown. But what if you use many thumbnail in UITableview, it will be heavy in the device. It's bad design too. It will be good for you, if you can combine this extension image with SDWebImage. Because the image will be in cache and you don't need to reload image again. But you still need the internet to load the video url. Because it's online from the internet. This is swift code and about objective-c code, it's better you search on the internet. I know it's really painful to change it to swift if you have developed big app. So you can convert

Create Rectangle Bubble Chat iOS Swift 5

Image
Hello all, every week I try to give you a good tutorial to add your skill and knowledge too. And today you got to be suprised because It's not usually tutorial. I need to dig it deep down to present it. So if you want to create chat application, it's good for you. You can take it as reference. So in chat application, you will face chat from bottom to up. As a screenshoot above, you can see it's not from top to bottom but otherwise. There is bubble chat on left and right. You can say when you send it will be on right and when someone send, it will be on left. And about text height, it must be flexible height. Like app chat line or whatsapp, there is no cut in height. So it can small or so high. So we need to calculate the height. And about the width it's not full, we give space to the right or left. I include the title header too so It will be more like chat app. The header will be on viewForFooterInSection why ? Because I reverse the UITableview, so the chat wi

Double Tap Zoom to The Tap Location Swift 5 iOS 13

Image
Hello, I find a problem where user wants to zoom to the tap location in ImageView. Actually ImageView inside UIScrollview. Because it's not just zoom when double tap but user can zoom manually with pinning. So basically it's like gallery album in iPhone, you can see it. When I try find the way on the internet, it doesn't work like the way I want. Double tap to zoom working but it just zoom on the center not to the tap location. You need to combine UIScrollview with UIImageview to use gesture zoom. Because UIImageview itself doesn't use scrollview so it will not effect scrollview. Maybe in iOS version before 13 the way on the internet it works. Because I see some posting get upvote and every comment say it works. But in new version of iOS we need to check again. So it's like swift version language. It has developed better again. So I finally combine answer on the internet to make what I want. So  this is the code

Avoid Create Multiple Album in iOS Swift 5

Image
Do you ever have an application that can download photo from your app to your album gallery ? It's not so complicated to do it, if you have the library that I will share to you right now. When you save your photo sometimes you need to create the album first then put the images in there. So It's neat too look. You can name your album with name of your app name. So the trick is everytime user will download you call create album method. In this method you check first if there's an same album created or not. If it's not then creating new one otherwise don't create. Because in iOS create same name, it's permitted. So it will be bad if you create many albums with same name. And if you reinstall the app, maybe the app will create the same album if you don't check. So it's our job as programmer to handle it. To make the user doesn't need to delete the same album. I personally want to know the way before I didn't reliaze that my app create multiple

Solution UIViewController Not Full Screen in iOS 13 ( Bonus My Extension )

Image
Good october month all. Have you installed iOS 13 in your device and you get suprise that some of your views have a gap on the top like picture above. It's bad or good news for us developer iOS. First it looks new and some people may love or hate it but in iOS 13 it becames default system to use it. You need to change it manually every view controller, if you have many it becames many job to do it. Why we need to change it back to fullscreen, because I have view that has not to come back to previous view. It will be bad for user expirience to swipe up and go back and what they get only splashscreen and don't go anywhere again. It needs to reopen app again. This is my case in my apps. Fortunely it's not hard to change it back to fullscreen again. It just needs one line code to change it but if you have function everytime you do presenting view controller. You just need to add one single line to make it fullscreen but if you have many present function in many classes

How to customize your date according to Timezone in Swift 5

Image
What if we want to unite time in different country for all users that install our app. Yes we can use one timezone for all users. Example we use Asia/Jakarta timezone then everyone who install our app will get same time. But you have to work together with your API developer, so API will send same timezone to all users. And in our app we will get it and convert it. It's not difficult to do it. I will show you how. I use swift 5, because that's latest one. I haven't used objective-c because no project that write use it. Swift actually more simple than objective-c but it's same. It uses iOS OS. Xcode is helpful tool to write iOS app. But if you use xamarin, it will be ok but the language is not same at all. You need to research again. You need to understand basic thing about timezone. What is your timezone in your country ? you need to know UTC and GMT because iOS use these.

How to disable UITableview ScrollView Pagination when Data is Still Fit In

Image
Hello guys, if you ever work with UITableview. Sometimes you need to do pagination and there many ways to do it. One of them is using scrollview. I want to share with you my improve way to do pagination because on the internet. It needs to improve a little bit. Why you need to do pagination because it will make your app run lightweight and more fast. Because you just load API as necessary. Many greats app use this and if there are images you don't load all. It's just load the first page one. Fortunately iOS support it and we can use UITableview to do it. UICollectionView can do it too but we talk it later on the next post. So check this out.

How to disable touch outside to dismiss and swipe in Side Menu Swift

Image
I find a problem where I need to disable side menu to dismiss. So basically it's just showing side menu and view controller behind it. I use library  https://github.com/kukushi/SideMenu  because I look it simple and it support swift 5. I need to custom it because in my side menu I have parent and children so I need to customize it manual. But in here I don't tell you how to do it because my focus is to disable touch outsude and swipe. Sometimes you need to do it in some UIViewController. And Side menu library don't explain it explicitly. So I need to figure it out by myself and it's not harder to do find it out. In Side Menu it works with gesture so I need to get all gesture and disable it according to what I want to disable. In this case swipe gesture and touch outside. You can see in my code I put it in ViewDidApper and ViewDidDisappear because I just want disabled feature in this only UIViewController.

How to set first day of week in DateRangePicker Calendar Android

Image
I have created an app called "To Do List Extra" that has a calendar. I found a issue that i need to set first of week to saturday or monday. By default calendar will be sunday. So i tried to ask on the internet and finally found the way. Locale will make a different first day of week. I just changed the locale and automatically the first day of week will be changed too. Why I need to set first of week because in different country we have diffrent first of week. In my country first of week is monday. It's very helpful we don't need to adjust the calendar. DateRangePicker is default Android library so it's not complicated to customize it. In my app We have to add task and put date and time if you want. I have notification timer so it will put banner notification when your task date and time is suitable with time right now. So basically it's important to set first of week.

Problem UICollectionViewController When Trying to Use bringSubview Swift 4

Hi guys, I found unique issue when trying to use bringSubview in UICollectionViewController. The method doesn't work if you try like this. UICollectionViewController has a diffrent to do add subview. Because it's not pure UIViewController itself or parent. It needs to get superview to add a new view. So basically you do like below and nothing happened or it doesn't work. Don't worry about it, i have a solution for you. It's simple way to do it and don't make you think too much. I find this idea on stackoverflow. I will put the link below. self . view ! . addSubview(something) self . view ! . bringSubview(toFront:   something) So to do trick you need to use superview!.

Change status bar text to white iOS Swift 4.2 Xcode 10.0

Image
Hello back guys, I'll show you guys how to change status bar text without coding. Just follow this screenshoot that I give. It's a peace of cake and you don't need to confused about it. I will tell you  simple way. But it's good to do programtically, it's just an option. Why we need to change status bar text because we sometimes need to costume our application with our theme. If you have good theme, customers will like you app and use it every time haha. You need to edit Info.plist to do it but xcode will do automatically if you change it Deployment info because it will change Info.plist when you edit it. I will give you a source code too what will change in Info.plist. Source code in Info.plist

Trick to Avoid Force Close Because of JSON Null Swift 4

Hi guys today I'm gonna share to you my extension to handle JSON null. You can change return default. So your app will never be force closed because of JSON null. So this is the code.

Extension Rotating Image Smoothly with Swift 4

Image
Do you ever want to do animation thing like rotating image continuously ? Today I want to give you a good way to do it. I make this a extension so it's easily to maintain :D. I found this trick on stackoverflow and implement it using swift.

Get Height Keyboard iOS Swift 4

Image
I have a problem when trying to use IQKeyboardManager. When keyboard show up, the navbar sometimes will break the top and give some white space. So finally i turn off IQKeyboardManager and trying to implement keyboard show up by self. So the point is to get height keyboard and raise the textbox above keyboard. This is the example of I've done.

How to convert HEX RGBA color in swift 4.2

Hello guys, today I wanna share with you a method or extenstion that I use to convert any hex rgba like this #33000000 which is One hash and 8 digit hex. 33 is for Alpa, 00 is R, 00 is G, 00 is B. You can modify the code appropriate what you want. So the code goes likes this.

Don't Use prefs:root= in Your iOS Apps

My client got an error when trying to submit the app to app store. So the message goes like this : Guideline 2.5.1 - Performance - Software Requirements Your app uses the "prefs:root=" non-public URL scheme, which is a private entity. The use of non-public APIs is not permitted on the App Store because it can lead to a poor user experience should these APIs change. prefs:root=wifi Continuing to use or conceal non-public APIs in future submissions of this app may result in the termination of your Apple Developer account, as well as removal of all associated apps from the App Store.

Create Colored Clickable Link Between text in UIlabel Swift 4.2

Image
Happy New 2019 although it's too late but i finally get a topic about what I want to post today. I have a solution for you guys who wants to make clickable link check it out. See this image when you click the link that has purple color you will redirect to external browser. I'll share the code, dont' worry :D