Ana sayfa iOS Swift – Navigation Bara activity Indicator Ekleme

Swift – Navigation Bara activity Indicator Ekleme


Merhaba arkadaşlar,

Bugünkü dersimizde Navigation Bara nasıl bir text eşliğinde activity Indicator ekleyebileceğimizi göreceğiz.

Storyboard çok basit olduğu için hızlıca geçeceğim.

Öncelikle bir Single View Application oluşturun, storyboard dosyanızı açın ve ViewControllerı yukarda editor kısmından Emberd In -> Navigation Controller’a tıklayarak bir navigation controller içine alın.

Ardından iki tane button ekleyin ve constraintleri dilediğiniz gibi ayarlayın. Ben butonlarımın title kısımlarını Start ve Stop olarak ayarladım. Daha sonra Assistant Editor yardımıyla Storyboard’dan ViewController’a her button için ayrı action outletleri ekleyin.

Benim storyboard ve ViewController.swift dosyam aşağıdaki gibi görünüyor. Sizinde buna benzer bir görüntüye sahip olmanız gerekir.

Şimdi gelin activityIndicator(yükleme belirteci) için bir sınıf oluşturalım. ActivityIndicator adında yeni bir Swift dosyası oluşturalım ve projemize ekleyelim.

Sonra dosyamızın içine aşağıdaki kodu kopyalayalım.

  1. Singleton oluşturuyoruz, daha detaylı açıklaması mevcut ancak kısaca, bir obje oluşturma ihtiyacı duymadan direk o objeye refer ederek işlemler yapmamızı sağlayan bir yapı. (Yakında singletonlar ve swift ile nasıl yazılacağıyla ilgili detaylı ders geliyor)
  2. activityLabel adında bir UILabel oluşturuyoruz, koordinatlarını genişlik ve yükseklik bilgisini giriyoruz.
  3. activityIndicator adında bir UIActivityIndicatorView oluşturuyoruz, koordinat ve boyutları girerek.
  4. activityView adında boş bir UIView objesi oluşturuyoruz.

Şimdi animasyonumuzu tasarlayabileceğimiz ve başlatabileceğimiz animateActivity adında title, view, ve navigationItem adlarında 3 parametre alan bir metod tanımlayalım.

  1. İlk önce daha önce oluşturduğumuz activityIndicator’ün stilini belirliyoruz. Ardından gene daha önce oluşturduğumuz activityLabel’ın text özelliğini, metodumuza aldığımız title parametresine eşitliyoruz.
  2. .sizeToFit() metoduyla Labelimizin boyutunun verilen title uzunluğuna eşit olmasını sağlıyoruz.
  3. xPoint ve yPoint adında iki sabit oluşturuyoruz. x noktasını view’ımızın çerçevesinin tam ortası olarak ayarken, y noktasını ise metodumuza parametre olarak aldığımız navigationItem’ın erişilebilen çerçevesinin tam orta noktasının y si olarak ayarlıyoruz. widtyForActivity sabitiylede, indicator ve label genişliklerini toplayarak activityView’e eşitliyoruz. (Not: navigationItem Navigation Controllerın yukardaki bar kısmının Swiftteki tanımlaması)
  4. activityIndicator ve activityLabel objelerini activityView’ımıza subview(alt view) olarak ekliyoruz.
  5. Daha sonra navigationItem parametresinin titleView özelliğini oluşturduğumuz activityView objemize eşitliyoruz, ve ardından activityIndicator.startAnimating() diyerek yükleniyor görüntümüzü navigasyon barımızda görüntülemeye başlıyoruz.

Şimdi ise stopAnimating adında gene navigationItem parametresi alan bir metod tanımlayalım. Bu metodumuzun amacı herhangi yükleme işlemimiz sona erdikten sonra, navigasyon barımızdaki yükleniyor ibarelerini ortadan kaldırmaya yarayacak.

Bu metodda ilk önce activityIndicator objemizi .stopAnimating() metodu ile durduruyoruz, ve ardından navigationItem’in titleView özelliğini nil’e eşitleyerek, daha önceden eklediğimiz activityView objesini silmiş oluyoruz.

Şimdi tekrar ViewController dosyamıza gidelim ve activityIndicator adında oluşturduğumuz ActivityIndicator sınıfından bir obje oluşturalım.

Sonra startTapped metodumuzun içersinde oluşturduğumuz objemizin .animateActivity metodunu tetikleyelim. title olarak dilediğimizi gönderebiliyoruz, ne yazdırmak istersek. View olarak self.view yazmamız gerekiyor çünkü activityIndicator’ü göstermek istediğimiz view, ViewController’ın kendi viewı. navigationItem olarakta, ViewControllerımız zaten bir navigation controller içerisinde gömülü olduğu için direk navigationItem diyoruz.

stopTapped metodumuzdada durdurma işlemini gerçekleştirelim:

Şimdi uygulamamızı çalıştıralım ve Start Stop butonlarına basarak nasıl çalıştığını görelim.

Navigation Bar Loading GIF - Find & Share on GIPHY

Bu dersimizinde sonuna geldik, artık dilediğiniz zaman projelerinizde, navigation bar üzerinde de activityIndicator kullanabilirsiniz.


  1. Have you ever thought about including a little bit more than just
    your articles? I mean, what you say is valuable and everything.
    Nevertheless imagine if you added some great photos or video clips to give your
    posts more, “pop”! Your content is excellent but with pics and video clips, this website could certainly be one of the greatest in its field.
    Superb blog!

  2. May I simply just say what a comfort to find somebody who truly knows what they are discussing over the internet.
    You definitely understand how to bring an issue to light
    and make it important. More and more people must read this and
    understand this side of your story. I can’t believe you are not more popular because you surely
    possess the gift.

  3. Awesome blog you have here but I was wanting to know if you knew of any user discussion forums
    that cover the same topics talked about in this
    article? I’d really like to be a part of community
    where I can get responses from other experienced individuals that share the
    same interest. If you have any suggestions, please let me
    know. Many thanks!

  4. Hello! I could have sworn I’ve been to this blog before but after browsing through some of the post I realized it’s new to me. Anyways, I’m definitely happy I found it and I’ll be book-marking and checking back frequently!

  5. Hey there! I could have sworn I’ve been to this blog before but after
    checking through some of the post I realized it’s new
    to me. Anyhow, I’m definitely happy I found it and I’ll be bookmarking and checking back often!

  6. Hey! Do you know if they make any plugins to help with SEO? I’m trying to get my blog to rank for some targeted keywords but I’m not seeing very good results. If you know of any please share. Kudos!

  7. Howdy just wanted to give you a quick heads up.
    The text in your article seem to be running
    off the screen in Firefox. I’m not sure if this is a formatting issue
    or something to do with browser compatibility but
    I figured I’d post to let you know. The style and design look great though!
    Hope you get the problem solved soon. Kudos

  8. Hi, i think that i saw you visited my blog thus i came to “return the favor”.I’m trying to find things to improve my website!I suppose its ok to use a few of your ideas!!

  9. Hi, i read your blog occasionally and i own a similar one and i was just curious if you get a lot of spam remarks?

    If so how do you prevent it, any plugin or anything you can advise?
    I get so much lately it’s driving me mad so any assistance is very much appreciated.

  10. Hi there! Do you know if they make any plugins to assist with SEO? I’m trying to get my blog to rank for some targeted keywords but I’m not seeing very good gains. If you know of any please share. Appreciate it!

  11. I know this if off topic but I’m looking into starting my own blog and was wondering what all is needed to get set up?
    I’m assuming having a blog like yours would cost a
    pretty penny? I’m not very internet smart so I’m not 100% certain. Any tips or advice would be greatly appreciated.
    Thank you

  12. Greetings! I know this is kinda off topic however I’d figured I’d ask. Would you be interested in exchanging links or maybe guest authoring a blog post or vice-versa? My website goes over a lot of the same topics as yours and I believe we could greatly benefit from each other. If you are interested feel free to send me an e-mail. I look forward to hearing from you! Wonderful blog by the way!

  13. Thanks for another informative site. Where else could I get that kind of info written in such an ideal way? I have a project that I’m just now working on, and I’ve been on the look out for such information.

  14. Heya i’m for the first time here. I found this board and I find It really useful & it helped me out much.

    I hope to give something back and help others like you aided me.

  15. Just desire to say your article is as amazing. The clearness in your post is just nice and i can assume you are an expert on this subject. Well with your permission let me to grab your RSS feed to keep updated with forthcoming post. Thanks a million and please keep up the gratifying work.

  16. I have been absent for a while, but now I remember why I used to love this blog. Thank you, I will try and check back more often. How frequently you update your website?

  17. Hi! Someone in my Myspace group shared this website with us so I came to look it over. I’m definitely loving the information. I’m bookmarking and will be tweeting this to my followers! Great blog and excellent style and design.

  18. What’s Happening i am new to this, I stumbled upon this I’ve found It positively helpful and it has aided me out loads. I hope to contribute & aid other users like its helped me. Great job.

  19. Hi, Neat post. There’s an issue together with your site in web explorer, may test thisK IE nonetheless is the marketplace leader and a good component to other people will omit your magnificent writing because of this problem.

  20. In this grand scheme of things you actually get an A+ for effort. Where you misplaced me was first in your particulars. You know, they say, the devil is in the details… And it couldn’t be much more accurate here. Having said that, let me say to you just what exactly did work. The text is certainly very persuasive which is possibly why I am making the effort in order to comment. I do not make it a regular habit of doing that. Next, even though I can easily notice the jumps in reasoning you come up with, I am not certain of exactly how you appear to connect the details that make the conclusion. For now I shall subscribe to your issue but hope in the future you connect your facts much better.

  21. You actually make it appear really easy along with your presentation however I to find this matter to be really something which I think I might never understand. It kind of feels too complicated and very vast for me. I am taking a look ahead for your subsequent put up, I?¦ll attempt to get the cling of it!

  22. I simply could not leave your website prior to suggesting that I really enjoyed the standard info a person provide on your guests? Is going to be back regularly to check up on new posts.

  23. I do like the way you have framed this specific difficulty plus it does supply us some fodder for consideration. However, because of just what I have personally seen, I just wish when other feed-back pile on that individuals keep on point and in no way start on a tirade associated with the news du jour. All the same, thank you for this exceptional piece and although I do not necessarily concur with the idea in totality, I value your perspective.

  24. I love your blog.. very nice colors & theme. Did you create this website yourself or did you hire someone to do it for you? Plz reply as I’m looking to create my own blog and would like to know where u got this from. kudos

  25. My coder is trying to persuade me to move to .net from PHP. I have always disliked the idea because of the costs. But he’s tryiong none the less. I’ve been using Movable-type on several websites for about a year and am nervous about switching to another platform. I have heard fantastic things about Is there a way I can import all my wordpress content into it? Any help would be really appreciated!

  26. Write more, thats all I have to say. Literally, it seems as though you relied on the video to make your point. You obviously know what youre talking about, why throw away your intelligence on just posting videos to your site when you could be giving us something informative to read?

  27. Pretty nice post. I simply stumbled upon your weblog and wanted to mention that I have truly enjoyed surfing around your blog posts. In any case I will be subscribing on your feed and I am hoping you write again soon!

  28. NEAUVIA,歐洲血統透明質酸,目前遍布於全世界56個國家,行政總部在瑞士,卻是源自於意大利的品牌。採用21世紀先進的技術,提取出前所未有的高純度透明質酸,迅速的在全球攻占市場,卓越的品質,領先的技術和平民的價位,已經逐漸的出現在大眾的視線裡,被越來越的人使用。NEAUVIA以系列分女性專用和男性專用,大中小分子以及唇部專用和私處專用,其中私處專用己經在國內一些比較大的整形機構普遍使用。素材提取無與倫比的純淨,運用嶄新PEG鏈結技術-更安全

  29. Wonderful paintings! This is the kind of information that are meant to be shared across the internet. Disgrace on the seek engines for not positioning this submit higher! Come on over and consult with my site . Thanks =)

  30. Thanks a bunch for sharing this with all people you actually realize what you’re speaking approximately! Bookmarked. Please also talk over with my website =). We may have a link change arrangement among us!

  31. Hi, Neat post. There is a problem together with your site in internet explorer, could check thisK IE nonetheless is the marketplace chief and a big part of other people will leave out your wonderful writing because of this problem.

  32. of course like your web-site but you need to check the spelling on quite a few of your posts. Several of them are rife with spelling issues and I find it very troublesome to tell the truth nevertheless I’ll certainly come back again.

  33. I have learn some just right stuff here. Certainly worth bookmarking for revisiting. I wonder how so much effort you put to make one of these wonderful informative site.

  34. Attractive component of content. I simply stumbled upon your blog and in accession capital to assert that I get in fact loved account your blog posts. Anyway I’ll be subscribing for your augment or even I achievement you get admission to persistently fast.

  35. Pretty great post. I just stumbled upon your blog and wished to mention that I’ve really loved browsing your blog posts. In any case I will be subscribing to your feed and I’m hoping you write again soon!

  36. Thanks for another excellent post. Where else could anybody get that type of information in such a perfect way of writing? I have a presentation next week, and I am on the look for such information.

  37. I liked as much as you’ll receive performed proper here. The comic strip is tasteful, your authored material stylish. nevertheless, you command get got an nervousness over that you would like be turning in the following. unwell indisputably come further until now once more since exactly the similar nearly very often within case you protect this increase.


Lütfen yorumunuzu giriniz
Buraya isminizi giriniz