i think cole valley and the inner sunset are very nice/safe neighborhoods (but tend to be foggy in the summer) and are within walking distance to ucsf. cole valley is more charming, thus more difficult to find an affordable apartment than the inner sunset. the inner sunset has lots of affordable restaurants that are pretty good. you could live past 19th ave (outer sunset) and take the n-judah (10 to 25 minute commute?), but there is not that much out there other than chinese neighborhoods, some neighborhood restaurants/shops (not all that nice in my opinion), etc... i guess it depends on what you're looking for. you are likely to find the most affordable places that are convenient to school in the outer sunset. it is a safe neighborhood.
the haight is ok (lots of shops/restaurants, lots of hippies -- not really my scene but maybe your's), though parking can be MISERABLE, so i wouldn't recommend it unless you don't have a car or get your own parking space. you could probably walk from the haight or else take a short bus ride.
duboce triangle is quite nice and a quick hop on the n-judah to ucsf (8-10 minutes?)
personally, i would avoid hayes valley/alamo square area. it has a lot of cute shops/restaurants, but is close to sketchy areas.
you could also live in the inner richmond (across the park, also foggy but inexpensive and has some restaurants/bars). i'm not sure how the public transportation is around there, though. the bus service is rather sporadic to ucsf i believe. laurel heights is a pretty nice neighborhood (though not really any bars around if you're into that), and there is a free shuttle (takes 15 minutes) that runs to ucsf on weedays that is very reliable. there is also a bus that goes there and takes maybe 25 minutes -- the 43 i think. most of the places on that bus line as you go north are pretty nice. also, as someone else mentioned, there is a free shuttle that goes to mt. zion. you could live around there, but might want to be careful about where you choose -- you probably don't want to live on the south side of mt. zion or if you do, you should make sure it's a safe neighborhood. it can get a bit sketchy. fillmore street north of sutter is very nice, lots of cafes and yuppies.
my absolute favorite neighborhood in sf is noe valley (sunnier than most mentioned above), but i don't know if there's a bus to ucsf
.
i agree that you should defintely check out craigslist. i was a little skeptical about finding roommates on the internet but used it twice and ended up with some great roommates.
good luck!